Assume there is a class A that contains a vector of ints. Now assume that a vector of A\'s is created. If a reallocation of an A object occurs (so the vector object is moved) du
Your A
elements will be moved where possible, and A
has an implicit move constructor and implicit move assignment operator, so the member vector will also be moved.
Now, moving a vector is not necessarily equivalent to a.swap(b)
, so you cannot rely on the implicit move functions if you want a guarantee; you could write your own.
But whether you guarantee it yourself or obtain a guarantee by looking up the code of your particular standard library implementation, you can be assured that pointers and iterators to the individual elements shall remain valid:
[C++11: 23.2.1/8]:
The expressiona.swap(b)
, for containersa
andb
of a standard container type other thanarray
, shall exchange the values ofa
andb
without invoking any move, copy, or swap operations on the individual container elements. [..]