This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/8965: Strange results with remove_if
- From: reichelt at igpm dot rwth-aachen dot de
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, joona dot kiiski at iki dot fi, nobody at gcc dot gnu dot org
- Date: 16 Dec 2002 22:26:31 -0000
- Subject: Re: c++/8965: Strange results with remove_if
- Reply-to: reichelt at igpm dot rwth-aachen dot de, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, joona dot kiiski at iki dot fi, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: Strange results with remove_if
State-Changed-From-To: open->closed
State-Changed-By: reichelt
State-Changed-When: Mon Dec 16 14:26:30 2002
State-Changed-Why:
Not a bug.
remove_if just copies the remaining elements to the beginning of the
container and returns an iterator that points to the new end. It does
not change the size of the container.
To correct your program, you could write something like this:
list<dummy*>::iterator newend = remove_if(mylist.begin(), mylist.end(), ptr_id_eq<dummy>(1));
for(list<dummy*>::iterator myiter = mylist.begin(); myiter != newend; myiter++)
cout<<(*myiter)->id<<"\n";
But you can do without all the hassle, just use the member-function:
mylist.remove_if(ptr_id_eq<dummy>(1));
which really does what you intended.
Regards,
Volker
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8965