iterators of which containers are "invariant" to what they point to upon insertion/deletion?
so far i found out that:
vector<>::iterator always points to the same entry in the vector.
thus if you have an iterator pointing to vector.begin(); and insert a new element to the beginning of the vector, the iterator will point to the new element
reason: vector is a linear piece of memory (array), and the iterator always points to the same location in that array. thus insertion requires shifting elements to the right.
if you have an iterator pointing to list.begin() and you insert a new element to the beginning, the iterator will still point to the old element
reason: list is a linked list. iterator points to some element in the list, and linked list elements' location in memory doesnt change as long as it exists (thus the location of the data is invariant upon indel (insertion/deletion)
what about map and set?
i know they use red/black tree structures for organizing their data.
but if i have an iterator to some element and keep indeling elements, does this iterator still point to the correct entry?
of course im not talking about erasing some iterator and useing it after that. of course that causes undefined behaviour.