Quickie: Can std::deque::push_back() invalidate its iterators?

B

bartek

Hi,

I'm sorry for asking such a simple question.
I just would like to know what's the standard-defined behaviour when doing
a push_back() on a std::deque.

TIA,
b
 
V

Victor Bazarov

bartek said:
I'm sorry for asking such a simple question.
I just would like to know what's the standard-defined behaviour when doing
a push_back() on a std::deque.

The answer is, yes, it does invalidate _all_ iterators. However,
unlike insertion into the middle of a deque, insertion into either
end does not invalidate the references to elements in the deque
(the Standard, 23.2.1.3).

Victor
 
A

Andre Kostur

The answer is, yes, it does invalidate _all_ iterators. However,
unlike insertion into the middle of a deque, insertion into either
end does not invalidate the references to elements in the deque
(the Standard, 23.2.1.3).

Victor, did you just contradict yourself? The OP asked about a push_back
(ie: insertion to the end of the deque), then you answered that it does
invalidate all iterators, but not if you insert into either end.
 
V

Victor Bazarov

Andre Kostur said:
Victor, did you just contradict yourself? The OP asked about a push_back
(ie: insertion to the end of the deque), then you answered that it does
invalidate all iterators, but not if you insert into either end.

Please reread my answer. Iterators and references are NOT the same thing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top