Add helper function for removing objects from STL containers. mem_fun() and mem_fun_ref() are handy for using const (?) member functions as predicates.
This commit is contained in:
@@ -95,6 +95,18 @@ void CircularShift( vector<T> &v, int dist )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function to remove all objects from an STL container for which the
|
||||
* Predicate pred is true. If you want to remove all objects for which the predicate
|
||||
* returns false, wrap the predicate with not1().
|
||||
*/
|
||||
template<typename Container, typename Predicate>
|
||||
inline void RemoveIf( Container& c, Predicate p )
|
||||
{
|
||||
c.erase( remove_if(c.begin(), c.end(), p), c.end() );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We only have unsigned swaps; byte swapping a signed value doesn't make sense.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user