PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > sequential container insert() function
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
sequential container insert() function

Réponse
 
LinkBack Outils de la discussion
Vieux 06/02/2008, 08h42   #1
subramanian100in@yahoo.com, India
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sequential container insert() function

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
  Réponse avec citation
Vieux 06/02/2008, 11h06   #2
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sequential container insert() function

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11590 seconds with 10 queries