stl::remove does NOT remove elements!

Mental note: stl::remove does NOT remove the elements in a collection. It merely moves the elements to the back of a collection and returns an iterator which points to the first element to be removed.

It can be used as follows:

  1.  
  2. #include <algorithm>
  3.  
  4. // more stuff here..
  5.  
  6. myCollection.erase(
  7. std::remove(
  8. myCollection.begin(),
  9. myCollection.end(),
  10. myObj),
  11. myCollection.end()
  12. );
  13.  
  14.  

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>