public member function

std::multiset::operator=

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

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

Parameters

x
A multiset object with the same class template parameters (Key, 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
// assignment operator with multisets
#include <iostream>
#include <set>
using namespace std;

int main ()
{
  int myints[]={ 19,81,36,36,19 };
  multiset<int> first (myints,myints+5);   // multiset with 5 ints
  multiset<int> second;                    // empty multiset

  second=first;                            // now second contains the 5 ints
  first=multiset<int>();                   // and first is 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: 5

Complexity

Linear on sizes (destruction, copy construction).

See also