unordered_multimap operator= in C++ Last Updated : 20 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The unordered_multimap::operator= is a built-in function in C++ STL which does three types of tasks which are explained below. Syntax (copying elements from different container) : unordered_multimap_name1 operator= (unordered_multimap_name2)Parameters: The function does not accepts any parameter. The container to the right is the one from which the elements are to be copied to the container in the left. Return Value: It does not return anything. Below program illustrates the above function: CPP // C++ program to illustrate the // unordered_multimap::operator= #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<int, int> sample1, sample2; // inserts key and element // in sample1 sample1.insert({ 10, 100 }); sample1.insert({ 50, 500 }); cout << "Key and Elements of Sample1 before copy are:"; for (auto it = sample1.begin(); it != sample1.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } cout << "\nThe size of sample2 before copy: " << sample2.size(); // operator= to copy sample2 = sample1; cout << "\nKey and Elements of Sample2 after copy are: "; for (auto it = sample2.begin(); it != sample2.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } return 0; } Output: Key and Elements of Sample1 before copy are:{50, 500} {10, 100} The size of sample2 before copy: 0 Key and Elements of Sample2 after copy are: {50, 500} {10, 100} Syntax (For moving elements from different container): unordered_multimap_name1 operator= (unordered_multimap_name2)Parameters: The function does not accepts any parameter. The container to the right is the one from which the elements are to be moved to the container in the left. The elements in the right container are destroyed after operator= is used. Return Value: It does not return anything. Below program illustrates the above function: CPP // C++ program to illustrate the // unordered_multimap::operator= #include <bits/stdc++.h> using namespace std; // Function to merge two lists unordered_multimap<char, char> merge(unordered_multimap<char, char> a, unordered_multimap<char, char> b) { unordered_multimap<char, char> temp(a); temp.insert(b.begin(), b.end()); return temp; } int main() { // declaration unordered_multimap<char, char> sample1, sample2, sample3; // inserts key and element // in sample1 sample1.insert({ 'a', 'A' }); sample1.insert({ 'g', 'G' }); // inserts key and element // in sample1 sample2.insert({ 'b', 'B' }); sample2.insert({ 'c', 'C' }); sample2.insert({ 'd', 'D' }); cout << "Key and Elements of Sample1 are: "; for (auto it = sample1.begin(); it != sample1.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } cout << "\nKey and Elements of Sample2 are: "; for (auto it = sample2.begin(); it != sample2.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } // merging and moved sample3 = merge(sample1, sample2); sample1 = sample3; cout << "\n\nKey and Elements of Sample1 are: "; for (auto it = sample1.begin(); it != sample1.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } return 0; } Output: Key and Elements of Sample1 are: {g, G} {a, A} Key and Elements of Sample2 are: {d, D} {b, B} {c, C} Key and Elements of Sample1 are: {c, C} {b, B} {d, D} {a, A} {g, G} Syntax (For assigning the elements from different list): unordered_multimap_name1 operator= (intitializer_list il)Parameters: It does not accepts any parameter, it has the list to the right which will be assigned to the container. Return Value: It does not returns anything. Below program illustrates the above function: CPP // C++ program to illustrate the // unordered_multimap::operator= #include <bits/stdc++.h> using namespace std; int main() { // declaration by using operator= unordered_multimap<int, int> sample1 = { { 1, 2 }, { 3, 4 }, { 5, 6 } }; cout << "Key and Elements of Sample1 are: "; for (auto it = sample1.begin(); it != sample1.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } // declaration by using operator= unordered_multimap<char, char> sample2 = { { 'a', 'A' }, { 'b', 'B' }, { 'c', 'C' } }; cout << "\n\nKey and Elements of Sample1 are: "; for (auto it = sample2.begin(); it != sample2.end(); it++) { cout << "{" << it->first << ", " << it->second << "} "; } return 0; } Output: Key and Elements of Sample1 are: {5, 6} {3, 4} {1, 2} Key and Elements of Sample1 are: {c, C} {b, B} {a, A} Comment More infoAdvertise with us Next Article Unordered Multimap in C++ STL G gopaldave Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-unordered_multimap +1 More Practice Tags : CPPMiscSTL Similar Reads Unordered Multimap in C++ STL In C++, the unordered_multimap is an unordered associative container that stores data in the form of key-value pairs. It is similar to unordered map, but it allows multiple elements with the same key. It provides fast insertion, deletion and search operations in O(1) time by using hashing.Example:C+ 7 min read unordered_multimap begin() and end() function in C++ STL The unordered_multimap::begin() is a built-in function in C++ STL that returns an iterator pointing to the first element in the container or to the first element in one of its buckets. Syntax: unordered_multimap_name.begin(n) Parameters: The function accepts one parameter. If a parameter is passed, 5 min read unordered_multimap size() function in C++ STL The unordered_multimap::size() is a built-in function in C++ STL which returns the size of the unordered_multimap. It denotes the number of elements in that container. Syntax: unordered_multimap_name.size() Parameters: The function does not accept any parameters. Return Value: It returns an integral 3 min read unordered_multimap empty() function in C++ STL The unordered_multimap::empty() is a built-in function in C++ STL which returns a boolean value. It returns true if the unordered_multimap container is empty. Otherwise, it returns false. Syntax: unordered_multimap_name.empty() Parameters: The function does not accept any parameter. Return Value: It 2 min read unordered_multimap insert() in C++ STL The function std::unordered_multimap::insert() is a built-in function in C++ STL that extends container by inserting new element in unordered_multimap. This function increases container size by one. The insert() function can be used to insert a single key-value pair, a complete unordered_map, initia 2 min read unordered_multimap emplace() function in C++ STL The unordered_multimap::emplace() is a built-in function in C++ STL which inserts a new {key, element} in the unordered_multimap container. The insertion is done automatically at the position according to the container's criterion. It increases the size of the container by one. Syntax: unordered_mul 2 min read unordered_multimap find() function in C++ STL The unordered_multimap::find() is a built-in function in C++ STL which returns an iterator which points to one of the elements which has the key k. If the container does not contain any element with key k, then it returns an iterator which points to the position which is past the last element in the 3 min read unordered_multimap count() function in C++ STL The unordered_multimap::count() is a built-in function in C++ STL that returns the number of elements in the container whose key is equal to the key passed in the parameter. Syntax: unordered_multimap_name.count(key) Parameters: The function accepts a single mandatory parameter key that specifies th 2 min read unordered_multimap clear() function in C++ STL The unordered_multimap::clear() is a built-in function in C++ STL which clears the contents of the unordered_multimap container. The final size of the container after the call of the function is 0. Syntax: unordered_multimap_name.clear() Parameters: The function does not accept any parameter. Return 2 min read unordered_multimap swap() function in C++ STL 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 u 3 min read Like