Deque iterators and references invalidation 
Author Message
 Deque iterators and references invalidation

Hi everybody!

There is a general question I was not able to answer myself.

In "STL Tutorial and Reference Guide . C++ Programming with the Standard
Template Library",
by David R. Musseer , Atul Saini.    Addison-Wesley. 1996 ISBN:
0-201-63398-1,
it is stated for the Deque (p.283) , that :
" The insert , push_front , and push_back member functions invalidate
all the iterators and references to the deque ".

The question is - how insertion by push_back only would invalidate all
iterators and references to the deque ?
The question arose after I had to implement some changes in my deque to
use iterators and some STL algorithms. Before we've been using access
member functions front() and back() to get references to the deque
before every  pushing at back and popping off the front.

Now , I am  not sure if I can keep iterators ( let's say to last
accessed element in the deque) valid after any push_back() . Updating
the iterators after any pushing at the back does not seem very
effective.

If I understood deque all iterators and references invalidation business
correctly?

Thanks in advance,

Alex



Mon, 07 May 2001 03:00:00 GMT  
 Deque iterators and references invalidation

Quote:

>Hi everybody!

>There is a general question I was not able to answer myself.

>In "STL Tutorial and Reference Guide . C++ Programming with the Standard
>Template Library",
>by David R. Musseer , Atul Saini.    Addison-Wesley. 1996 ISBN:
>0-201-63398-1,
>it is stated for the Deque (p.283) , that :
>" The insert , push_front , and push_back member functions invalidate
>all the iterators and references to the deque ".

The C++ standard states that as long as you're inserting at either end of
the deque, only the iterators are invalidated.

Quote:
>The question is - how insertion by push_back only would invalidate all
>iterators and references to the deque ?
>The question arose after I had to implement some changes in my deque to
>use iterators and some STL algorithms. Before we've been using access
>member functions front() and back() to get references to the deque
>before every  pushing at back and popping off the front.

>Now , I am  not sure if I can keep iterators ( let's say to last
>accessed element in the deque) valid after any push_back() . Updating
>the iterators after any pushing at the back does not seem very
>effective.

Adding items to a deque invalidates all the iterators, so it doesn't look
like you're going to be able to keep the iterators.

--
Doug Harrison



Mon, 07 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. iterator invalidation by deque::insert

2. Index's for vector and deque in preference to iterators

3. deque iterator++ and function end() don't work on big structures

4. Bug in Deque Iterator

5. std::deque<T> iterators

6. Vector, list or deque back() and reference ?

7. Iterator and const Iterator?

8. Prevent Entire Client window Invalidation on Resizing

9. Concept Q: string reference type is not behave in reference using = sign

10. Web reference vs local reference

11. no reference ... *is* a reference

12. Obj A references Obj B which in turn references Obj A

 

 
Powered by phpBB® Forum Software