C++0x (using lambdas):
container.erase( std::remove_if( container.begin(), container.end(),
[]( int v ) { return v > 2; } ),
container.end() );
The reason for the erase
combined with the remove_if
is that STL algorithms apply to iterators, and not containers. They relocate the contents of the container, but they do not modify the container per-se.
C++03:
container.erase( std::remove_if( container.begin(), container.end(),
std::bind2nd( std::greater<int>(), 2 ) ),
container.end() );
This may seem a little simpler, but it is also less flexible, as there are only so many predicates already defined. For more complex operations you would have to write your own predicate functor.