c++/8965: Strange results with remove_if
reichelt@igpm.rwth-aachen.de
reichelt@igpm.rwth-aachen.de
Mon Dec 16 14:26:00 GMT 2002
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
More information about the Gcc-bugs
mailing list