I'm bit confused regarding iterator invalidation in deque. (In the context of this question)
Following is the excerpts from -- The C++ Standard Library: A Tutorial and Reference, By Nicolai M. Josuttis
Any insertion or deletion of elements other than at the beginning or end invalidates all pointers, references, and iterators that refer to elements of the deque.
Following is the excerpts from SGI site:
The semantics of iterator invalidation for deque is as follows. Insert (including
push_front
andpush_back
) invalidates all iterators that refer to a deque. Erase in the middle of a deque invalidates all iterators that refer to the deque. Erase at the beginning or end of a deque (includingpop_front
andpop_back
) invalidates an iterator only if it points to the erased element.
IMHO, deque is collection of blocks with first block growing in one direction and the last block in opposite direction.
- - -
- - -
| - - ^
| - - |
V - - |
- - -
- - -
push_back, push_front
should not have any impact on deque iterators ( I agree with Josuttis).
What is the correct explanation? what the standard say on this?
See Question&Answers more detail:os