std::list::remove_if predicate
This is an example of a predicate to be used with std::list::remove_if.
template <class T> class CHECK_RETIRE : public std::unary_function<T,bool>
{
private:
time_t now;
public:
CHECK_RETIRE(time_t n) : now (n) { }
bool operator() ( T val )
{
// T is a shared_ptr. If the member ->retire is less than now, return true to remove me.
return val->retire < now;
}
};
// Usage
struct CHECK
{
time_t retire;
}
typedef boost::shared_ptr<CHECK> CHECK_ptr;
std::list<CHECK> checklist:
/* add stuff */
time_t now = 1000;
checklist.remove_if( CHECK_RETIRE<CHECK>(now) );
// Items with ->retire less than 1000 is now removed from the list.