Article View: comp.std.c++
Article #2512Re: Modifying STL containers via an iterator
From: Dick Menninger
Date: Fri, 10 Nov 1995 20:13
Date: Fri, 10 Nov 1995 20:13
42 lines
1703 bytes
1703 bytes
> ==========b.c., 11/6/95==========
>
> Does the STL define the case where a container is modified while
> iterating through it?
>
> Example: (forgive me if the syntax isn't perfect...)
>
> class X x;
>
> for (X::iterator ix=x.begin(); ix != x.end(); ix++) {
> ix.erase();
> }
>
> Brian
> ( bcwhite@bnr.ca )
>
> -----------------------------------------------------------------
This assumes that ix does not change during erase()
and so that the range is the same. This form is
inherently problematic. So, lets try a better form for the
problem.
class X x;
for ( X::iterator ix=x.begin(); ix != x.end(); ix.erase() );
where ix.erase() changes ix to continue to "point to" a
valid value or to x.end() when none are left.
How about this case?
Good Day
Dick
Dick.Menninger@DaytonOH.ATTGIS.COM
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<DHuEA0.K2q@falcon.daytonoh.attgis.com>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<47l8qe$9fk@bcarh8ab.bnr.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: Dick Menninger <Dick.Menninger@daytonoh.attgis.com> Newsgroups: comp.std.c++ Subject: Re: Modifying STL containers via an iterator Date: 10 Nov 1995 20:13:31 GMT Organization: AT&T Global Information Solutions Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <DHuEA0.K2q@falcon.daytonoh.attgis.com> References: <47l8qe$9fk@bcarh8ab.bnr.ca> Reply-To: mennid <Dick.Menninger@daytonoh.attgis.com> NNTP-Posting-Host: physics2.berkeley.edu