C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Quick question...

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
deancoo
Guest





PostPosted: Fri Feb 25, 2005 6:17 am    Post subject: Quick question... Reply with quote



If I have a container, say a vector, with 5 elements, and I initialize
iterator variables to point to the beginning and end of the container, are
those iterators going to always be valid if I replace the elements of the
container? The size stays the same. It seems to be working now, but I
thought I read somewhere something about this not always working out. Any
thoughts?

d


Back to top
Alf P. Steinbach
Guest





PostPosted: Fri Feb 25, 2005 7:02 am    Post subject: Re: Quick question... Reply with quote



* deancoo:
Quote:
If I have a container, say a vector, with 5 elements, and I initialize
iterator variables to point to the beginning and end of the container, are
those iterators going to always be valid if I replace the elements of the
container? The size stays the same. It seems to be working now, but I
thought I read somewhere something about this not always working out. Any
thoughts?

Replacement is OK, insertion or deletion is not.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Thomas Maier-Komor
Guest





PostPosted: Fri Feb 25, 2005 9:01 am    Post subject: Re: Quick question... Reply with quote



Alf P. Steinbach wrote:
Quote:
* deancoo:

If I have a container, say a vector, with 5 elements, and I initialize
iterator variables to point to the beginning and end of the container, are
those iterators going to always be valid if I replace the elements of the
container? The size stays the same. It seems to be working now, but I
thought I read somewhere something about this not always working out. Any
thoughts?


Replacement is OK, insertion or deletion is not.


yes, but only for a vector. a map or set will resort its content
and therefore invalidate iterators...

--
________________________________________________________________________
Dipl.-Ing. Thomas Maier-Komor http://www.rcs.ei.tum.de
Institute for Real-Time Computer Systems (RCS) fon +49-89-289-23578
Technische Universitaet Muenchen, D-80290 Muenchen fax +49-89-289-23555

Back to top
Alf P. Steinbach
Guest





PostPosted: Fri Feb 25, 2005 9:48 am    Post subject: Re: Quick question... Reply with quote

* Thomas Maier-Komor:
Quote:
Alf P. Steinbach wrote:
* deancoo:

If I have a container, say a vector, with 5 elements, and I initialize
iterator variables to point to the beginning and end of the container, are
those iterators going to always be valid if I replace the elements of the
container? The size stays the same. It seems to be working now, but I
thought I read somewhere something about this not always working out. Any
thoughts?


Replacement is OK, insertion or deletion is not.


yes, but only for a vector. a map or set will resort its content
and therefore invalidate iterators...

Nope.

However, you're right the OP wrote "container", I didn't see that.

In general the question's answer depends on the container, that's why I didn't
see that (like, if I have a hungry animal, say a dog that's got no food for
three days, will it eat a raw steak?).

My imaging system has powerful nonsense-filtering built-in... ;-)

For associative containers, that's maps and sets:

§23.1.2/8: "The insert members shall not affect the validity of
iterators and references to the container, and the erase member shall
invalidate only iterators and references to the erased elements."

There is no resorting requirement, and if resorting takes place §23.1.2/8
restricts its effect on iterators and references.

Replacement for an associative container is to replace the value of a pair,
not the key (which cannot be replaced), and that does not affect iterators or
references. Replacement for a vector or list or queue (not only vector) does
not effect iterators and references. In short, value replacement is OK
(unless one argumentatively regards swap as a replacement), insertion and
deletion depends on the container in question.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.