public member function
<unordered_set>

std::unordered_multiset::operator=

copy (1)
unordered_multiset& operator= ( const unordered_multiset& ums );
move (2)
unordered_multiset& operator= ( unordered_multiset&& ums );
initializer list (3)
unordered_multiset& operator= ( intitializer_list<value_type> il );
Assign content
Assigns ums (or il) as the new content for the container.

The elements contained in the object before the call are destroyed, and replaced by those in unordered_multiset ums or initializer list il, if any.

The first version (1) performs a copy assignment, which copies all the elements of ums into the container object (with ums preserving its contents).

The second version (2) performs a move assignment, which transfer ownership of the contents of ums to the object. No copies occur: the content is lost by ums.

The third version (3) assigns the contents of the initializer list il as the elements of the container object.

Parameters

ums
An unordered_multiset object of the same type (i.e., with the same template parameters).
il
An initializer_list object. The compiler will automatically construct such objects from initializer list declarators.
Member type value_type is the type of the elements in the container, defined in unordered_multiset as an alias of its first template parameter (Key).

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
23
24
// unordered_multiset::operator=
#include <iostream>
#include <string>
#include <unordered_set>

template<class T>
T cmerge (T a, T b) {
  T t(a); t.insert(b.begin(),b.end()); return t;
}

int main ()
{
  std::unordered_multiset<std::string> first, second, third;
  first = {"red","green","blue"};      // init list
  second = {"red","yellow","blue"};    // init list
  third = cmerge (first, second);      // move
  first = third;                       // copy

  std::cout << "first contains:";
  for (const std::string& x: first) std::cout << " " << x;
  std::cout << std::endl;

  return 0;
}


Possible output:
first contains: blue blue red red yellow green

Complexity

For the copy assignment (1): Linear in sizes (destructions, copies).
For the move assignment (2): Linear in current container size (destructions).*
For the initializer list assignment (3): On average, linear in sizes (destructions, move-assignments) -- worst case: quadratic.
* Additional complexity for assignments if allocators do not propagate.

Iterator validity

All iterators, references and pointers to elements that were in the container before the call are invalidated.

See also

  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23
  • 3891941586 2018-02-23
  • 6039851585 2018-02-23
  • 2573991584 2018-02-23
  • 7728781583 2018-02-23
  • 3731582 2018-02-23
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22