Assigns x (or il) as the new content for the container.
Any elements contained in the object before the call are removed form the container and destroyed. They are replaced by those in x (or il), if any.
The copying assignment (1) copies all the elements in x into the container object (with x preserving its contents).
The move assignment (2) transfer ownership of the contents of x to the object (x loses its content and becomes empty).
A deque object of the same type (i.e., with the same template parameters, T and Alloc).
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 deque as an alias of its first template parameter (T).
Return value
*this
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// assignment operator with deques
#include <iostream>
#include <deque>
int main ()
{
std::deque<int> first (3); // deque with 3 zero-initialized ints
std::deque<int> second (5); // deque with 5 zero-initialized ints
second = first;
first = std::deque<int>();
std::cout << "Size of first: " << int (first.size()) << '\n';
std::cout << "Size of second: " << int (second.size()) << '\n';
return 0;
}
Output:
Size of first: 0
Size of second: 3
Complexity
For the copy assignments: Linear in sizes before and after the operation (destructions, copy constructions).
For the move assignment: Linear in current container size (destructions).
Iterator validity
All iterators, references and pointers related to this container before the call are invalidated.
In the move assignment, iterators, pointers and references referring to elements in x remain valid, but are now referring to elements in the container that acquires the elements (this does not include the end iterator).
Data races
All copied elements are accessed.
The move assignment (2) modifies x.
The container and all its elements are modified.
Exception safety
Basic guarantee: if an exception is thrown, the container is in a valid state.
It throws if the constructor of any element throws or if the internal allocator object throws attempting to allocate storage.