Pointer instability means that it is undefined behaviour to:
1) store (both on stack and heap) the pointer address to a value element outside of its respective container
2) then modify the container's content
3) then thereafter use the stored pointer address
This implies that:
- containers without pointer stability require pass-by-value (or a pointer to a temp copy) to be used for its values after accessing them OR
- containers without pointer stability require absolute immutibility of the container to guarantee runtime safety OR
- containers without pointer stability require "relative" immutability during the existence of a pointer to a value element to guarantee runtime safety. Note that I think this last option is a bad idea, because it requires multithreaded blocking/synchronization of the container and is also easy to encapsulate wrongly, leading to UB.
... with a specific set of mutating operations that (may) alter the container's structure (eg, element insertions and removals).
Altering the value of one element of the container doesn't invalidate iterators or references to any element. You can make as many mutating passes over a std::vector as you like without invalidating anything.
Things only start to get dicey when you push_back(), insert(), erase(), etc.
Pointer instability means that it is undefined behaviour to:
1) store (both on stack and heap) the pointer address to a value element outside of its respective container
2) then modify the container's content
3) then thereafter use the stored pointer address
This implies that:
- containers without pointer stability require pass-by-value (or a pointer to a temp copy) to be used for its values after accessing them OR
- containers without pointer stability require absolute immutibility of the container to guarantee runtime safety OR
- containers without pointer stability require "relative" immutability during the existence of a pointer to a value element to guarantee runtime safety. Note that I think this last option is a bad idea, because it requires multithreaded blocking/synchronization of the container and is also easy to encapsulate wrongly, leading to UB.