From e76f7c7902f6523b099c8556e13e55d5f35969c0 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 19 Feb 2006 06:04:34 +0000 Subject: [PATCH] Add helper function for removing objects from STL containers. mem_fun() and mem_fun_ref() are handy for using const (?) member functions as predicates. --- stepmania/src/RageUtil.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 0ab42ee7ca..6d248f0769 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -95,6 +95,18 @@ void CircularShift( vector &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 +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. *