Why does this code
#include
#include
#include
int main()
{
std::vector v;
v.push_back(1
Iterators corresponding to elements are only invalidated when the vector has to be reallocated, which reserve
avoids.
However, v.end()
won't stay valid.
The Standard's description of push_back
and insert
guarantees that
Causes reallocation if the new size is greater than the old capacity. If no reallocation happens, all the iterators and references before the insertion point remain valid.
v.end()
is not "before the insertion point".