public member function
<unordered_map>
std::unordered_map::operator=
| copy (1) | unordered_map& operator= ( const unordered_map& ump ); |
|---|---|
| move (2) | unordered_map& operator= ( unordered_map&& ump ); |
| initializer list (3) | unordered_map& operator= ( intitializer_list<value_type> il ); |
Assign content
The elements contained in the object before the call are destroyed, and replaced by those in unordered_map ump or initializer list il, if any.
The first version (1) performs a copy assignment, which copies all the elements of ump into the container object (with ump preserving its contents).
The second version (2) performs a move assignment, which transfer ownership of the contents of ump to the object. No copies occur: the content is lost by ump.
The third version (3) assigns the contents of the initializer list il as the elements of the container object.
Parameters
- ump
- An unordered_map 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 contained in the unordered_map, which is pair<const key_type,mapped_type>, where member type key_type is an alias of the first template parameter (the key type), and mapped_type is an alias of the second template parameter (the mapped type, T).
Return value
*thisExample
|
|
Possible output:
first contains: MSFT:Microsoft AAPL:Apple GOOG:Google ORCL:Oracle
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
- unordered_map::unordered_map
- Construct unordered_map (public member function)
- unordered_map::emplace
- Construct and insert element (public member function)