public member function

std::multimap::operator=

<map>
multimap<Key,T,Compare,Allocator>&
     operator= ( const multimap<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 multimap x, if any.

After a call to this member function, both the multimap object and x will have the same size and compare equal to each other.

Parameters

x
A multimap 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
22
// assignment operator with multimaps
#include <iostream>
#include <map>
using namespace std;

int main ()
{
  multimap<char,int> first;
  multimap<char,int> second;

  first.insert(pair<char,int>('x',32));
  first.insert(pair<char,int>('y',64));
  first.insert(pair<char,int>('y',96));
  first.insert(pair<char,int>('z',128));

  second=first;                // second now contains 4 ints
  first=multimap<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: 4

Complexity

Linear on sizes (destruction, copy construction).

See also