stl::remove does NOT remove elements!

August 23rd, 2007 Leave a comment Go to comments

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:

 
#include <algorithm>
 
// more stuff here..
 
myCollection.erase(
  std::remove(
    myCollection.begin(),
    myCollection.end(),
    myObj),
  myCollection.end()
  );
 
  1. No comments yet.
  1. No trackbacks yet.