戻り値を単純に否定できます。
bool Bar::filterFoo(Foo& foo)
{
return (std::find_if(filters.begin(), filters.end(), !boost::lambda::bind(boost::lambda::_1, foo)) == filters.end());
}
または、c++0X のラムダを使用できます
bool Bar::filterFoo(Foo& foo)
{
return (std::find_if(filters.begin(), filters.end(), [&foo](filter_function& f){
return !f(foo);
}
) == filters.end());
}
少なくとも VS2010 で機能する完全な例を示します。
#include <iostream>
#include <vector>
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/bind.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
struct Foo{};
typedef boost::function<bool (Foo)> filter_function;
std::vector<filter_function> filters;
static int g_c = 0;
bool MyFunc(Foo /*foo*/)
{
if(g_c > 1)
return true;
g_c++;
return false;
}
bool filterFoo(Foo& foo)
{
return (std::find_if(filters.begin(), filters.end(), boost::lambda::bind(boost::lambda::_1, foo)) == filters.end());
}
bool negatefilterFoo(Foo& foo)
{
return (std::find_if(filters.begin(), filters.end(), !boost::lambda::bind(boost::lambda::_1, foo)) == filters.end());
}
int main()
{
Foo f;
filters.push_back(boost::bind(&MyFunc, _1));
filters.push_back(boost::bind(&MyFunc, _1));
filters.push_back(boost::bind(&MyFunc, _1));
std::cout << filterFoo(f) << std::endl;
std::cout << negatefilterFoo(f) << std::endl;
return 0;
}
私のマシンでは 0 と 1 が返されます。