tags:

views:

91

answers:

1

Hello,

It might be a stupid question but just wonder if there is any workaround. :)

Is there any way to have "Not" in Predicate?

Example:

std::remove_if(s.begin(), s.end(), !IsCorrect); 
//                                 ^

Or, Do I have to create IsNotCorrect function anyways?

+10  A: 

You can do it using std::not1, which negates a unary predicate:

#include <functional>

std::remove_if(s.begin(), s.end(), std::not1(std::ptr_fun(IsCorrect)));

If IsCorrect is an Adaptable Function then you don't need ptr_fun, but if it's just a plain function then you do.

Steve Jessop
that's awesome..
Michael Sync