The elements contained in the object before the call are dropped, and replaced by copies of those in vector x, if any.
After a call to this member function, both the list object and x will have the same size and compare equal to each other.
Parameters
- x
- A list object containing elements of the same type.
Return value
*thisExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Both list containers of int elements are initialized to sequences with different sizes. Then, second is assigned to first, so both are now equal and with a size of 3. And then, first is assigned to a newly constructed empty container object, so its size is finally 0. Output:
Size of first: 0 Size of second: 3 |
Complexity
Linear on sizes (destruction, copy construction).See also
| list::assign | Assign new content to container (public member function) |
