Brett Hutley's Blog

Home on the Digital Range

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:

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