Article View: comp.std.c++
Article #2598Does remove_if invalidate iterators?
From: Bowden Wise
Date: Thu, 16 Nov 1995 18:57
Date: Thu, 16 Nov 1995 18:57
34 lines
1551 bytes
1551 bytes
I am using the remove_if () construct to remove a series of values
from a list<int> ... I am doing a loop like this:
list<int>::const_iterator next (l.begin());
list<int>::iterator last (l.begin());
while ( next != l.end() )
{
// increment before remove_if
list<int>::const_iterator cur ( next++ );
int val = *cur;
if ( val*val > MAX )
break;
//
last = remove_if (last, l.end(), bind2nd (myPred, val));
}
However, I am finding that each time remove_if is called, it *skips* the next
item in the sequence. So, does the remove_if mess up the semantics of my
iterator? What should I do?
--------------------------------------------------------------------
G. Bowden Wise
Computer Science Dept, Rensselaer Polytechnic Inst, Troy, NY 12180
Email: wiseb@cs.rpi.edu WWW: http://www.cs.rpi.edu/~wiseb/
[ 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:
<48g1hu$gf9@engnews1.eng.sun.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: Bowden Wise <wiseb@cs.rpi.edu> Newsgroups: comp.std.c++ Subject: Does remove_if invalidate iterators? Date: 16 Nov 1995 18:57:02 GMT Organization: ? Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <48g1hu$gf9@engnews1.eng.sun.com> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Mailer: MH 6.7.1 (exmh 1.5.1) Content-Length: 847 X-Lines: 30 Originator: clamage@taumet