This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/8965: Strange results with remove_if


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]