The standard guarantees that no links / iterators will be invalidated during, for example, pop_back
. From [container.requirements.general]:
Unless otherwise specified (explicitly or by defining a function in terms of other functions), referring to a member function of a container or passing a container as an argument, library functions should not invalidate iterators or change the values โโof objects in this container.
And there is no other specification, for example. pop_back
Thus, this means that redistribution cannot occur. 1
<Sub> 1. In the comments to another answer, it was suggested that, possibly, the memory corresponding to the pop-up element can be freed, which will not lead to the cancellation of references to "live" elements.
But then this will prevent re-growth of the array, as the standard states that inserts cannot cause redistribution until the size exceeds capacity. From [vector.capacity]:
It is guaranteed that redistribution does not occur during insertions that occur after the call to reserve()
until the insertion makes the vector size larger than the value of capacity()
.
sub>
source share