Search code examples
c++pointersdeque

Deque erase from middle, is pointer lost?


i erase elements from middle of my deque frequently. memory address of elements in deque are used in some other places. does erasing middle element from deque invalided all pointers to deque like it does with vectors? should i switch to list?(i iterate whole deque anyways)

i tried to read deque implementation but it is complex, i don't understand if it acts as a list or vector.

I'm using visualc++ std implementation of deque.


Solution

  • Yes. An insertion in the middle invalidates all iterators and references to elements (and thus pointers to elements). An insertion at either end invalidates all iterators, but not references or pointers. And you don't read the implementation to find out such things; you read the documentation. (The implementation may actually allow operations which aren't officially supported. Until the next bug fix.)