|
map::operator=
public member function
map<Key,T,Compare,Allocator>&
operator= ( const map<Key,T,Compare,Allocator>& x );
Copy container content
Assigns a copy of the elements in x as the new content for the container.
The elements contained in the object before the call are dropped, and replaced by copies of those in map x, if any.
After a call to this member function, both the map object and x will have the same size and compare equal to each other.
Parameters
- x
- A map object with the same class template parameters (Key, T, Compare and Allocator).
Return value
*this
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// assignment operator with maps
#include <iostream>
#include <map>
using namespace std;
int main ()
{
map<char,int> first;
map<char,int> second;
first['x']=8;
first['y']=16;
first['z']=32;
second=first; // second now contains 3 ints
first=map<char,int>(); // and first is now empty
cout << "Size of first: " << int (first.size()) << endl;
cout << "Size of second: " << int (second.size()) << endl;
return 0;
}
|
Output:
Size of first: 0
Size of second: 3
|
Complexity
Linear on sizes (destruction, copy construction).
See also
map::map | Construct map (public member function) |
|