The
unordered_multimap::swap() is a built-in function in C++ STL which swaps the contents of two unordered_multimap containers. The sizes can differ of both the containers.
Syntax:
unordered_multimap_name1.swap(unordered_multimap_name2)
Parameters: The function accepts a single mandatory parameter
unordered_multimap_name2 which specifies the unordered_multimap with which the swapping of
unordered_multimap_name1 is to be done.
Return Value: It does not return anything.
Below programs illustrates the above function:
Program 1:
Output:
Key and Elements of Sample1 before swap are:{50, 500} {10, 100}
Key and Elements of Sample2 before swap are:{20, 200} {30, 150} {30, 300}
Key and Elements of Sample1 after swap are:{20, 200} {30, 150} {30, 300}
Key and Elements of Sample2 after swap are:{50, 500} {10, 100}
Program 2:
Output:
Key and Elements of Sample1 before swap are:{g, G} {a, A}
Key and Elements of Sample2 before swap are:{d, D} {b, B} {c, C}
Key and Elements of Sample1 after swap are:{d, D} {b, B} {c, C}
Key and Elements of Sample2 after swap are:{g, G} {a, A}