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:
Steve Checkoway
2006-02-19 06:04:34 +00:00
parent c57798bf09
commit e76f7c7902
+12
View File
@@ -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.
*