|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Suppose I have a vector<T> or deque<T> for some type T.
Suppose vector<T>::iterator iter is an iterator. Then consider the operation vector<T>::iterator nit = container.insert(iter, T()); After the insertion, iter will be invalidated for both vector<T>, deque<T>. However for list<T>, the same operation under g++ 3.4.3, does not seem to invalidate iter. From this, can it be concluded that list<T> does not invalidate iterators after insert operation ? What does the standard say regarding this ? Kindly clarify. Thanks V.Subramanian |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 9:42 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.com> wrote: > Suppose I have a vector<T> or deque<T> for some type T. > Suppose vector<T>::iterator iter is an iterator. > Then consider the operation > vector<T>::iterator nit = container.insert(iter, T()); > After the insertion, iter will be invalidated for both vector<T>, > deque<T>. > However for list<T>, the same operation under g++ 3.4.3, does > not seem to invalidate iter. From this, can it be concluded > that list<T> does not invalidate iterators after insert > operation ? What does the standard say regarding this ? That some operations invalidate iterators, and others don't, and that which operations invalidate which iterators depends on the container. Each container has its own set of rules. In the case of insert: insert never invalidates iterators in std::list, nor any of the associative containers. In std::vector, it always invalidates iterators after the element inserted, and will invalidate all iterators if the capacity is increased. In std::deque, it invalidates all iterators. -- James Kanze (GABI Software) email:james.kanze@gmail.com Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 |
|
![]() |
| Outils de la discussion | |
|
|