multimap::swap | public member function |
void swap ( map<Key,T,Compare,Allocator>& mmp ); |
Swap content
Exchanges the content of the container with the content of mmp, which is another multimap object containing elements of the same type. Sizes may differ.
After the call to this member function, the elements in this container are those which were in mmp before the call, and the elements of mmp are those which were in this. All iterators, references and pointers remain valid for the swapped objects.
Notice that a global algorithm function exists with this same name, swap, and the same behavior.
Parameters
- mmp
- Another multimap container of the same type as this whose content is swapped with that of this container.
Return value
noneExample
// swap multimaps #include <iostream> #include <map> using namespace std; int main () { multimap<char,int> foo; multimap<char,int> bar; multimap<char,int>::iterator it; foo.insert(pair<char,int>('x',100)); foo.insert(pair<char,int>('y',200)); bar.insert(pair<char,int>('a',11)); bar.insert(pair<char,int>('b',22)); bar.insert(pair<char,int>('a',55)); foo.swap(bar); cout << "foo contains:\n"; for ( it=foo.begin() ; it != foo.end(); it++ ) cout << (*it).first << " => " << (*it).second << endl; cout << "bar contains:\n"; for ( it=bar.begin() ; it != bar.end(); it++ ) cout << (*it).first << " => " << (*it).second << endl; return 0; } |
Output:
foo contains: |
Complexity
Constant.See also
swap