negating a functor in a remove_copy_if

Hello everyone,
I couldn't figure out how to use a logical negation in the following situation.
struct IsConditionValid : public unary_function

Hello
I couldn't figure out how to use a logical negation in the following situation.
struct IsConditionValid : public unary_function
{ public: bool operator() (const Event& event)const {} }; remove_copy_if(events.begin(), events.end(), back_inserter(result), IsConditionValid()); <-- how to negate the condition object?
What I really need is '! IsConditionValid()'.
How can it be done using may be boost::bind ?
If you already have a unary predicate (as your IsConditionValid functor),
you can also use the std::not1 function to negate the predicate:
remove_copy_if(
events.begin(), events.end(),
back_inserter(result),
not1(IsConditionValid())
);
Bind overloads the ! operator for your convenience
#include

On 3/6/08, Jean-Pierre Bergamin
Hello
I couldn't figure out how to use a logical negation in the following situation.
struct IsConditionValid : public unary_function
{ public: bool operator() (const Event& event)const {} }; remove_copy_if(events.begin(), events.end(), back_inserter(result), IsConditionValid()); <-- how to negate the condition object?
What I really need is '! IsConditionValid()'.
How can it be done using may be boost::bind ?
If you already have a unary predicate (as your IsConditionValid functor), you can also use the std::not1 function to negate the predicate:
remove_copy_if( events.begin(), events.end(), back_inserter(result), not1(IsConditionValid()) );
Bind overloads the ! operator for your convenience
#include
... remove_copy_if( events.begin(), events.end(), back_inserter(result), !boost::bind(IsConditionValid(), _1) );
Thanks Jean-Pierre. That did the trick.
participants (2)
-
Jean-Pierre Bergamin
-
PJ Durai