1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
template <typename Fun>
struct not_fn_
{
Fun const &d_fun;
not_fn_(Fun const &fun)
:
d_fun(fun)
{}
template <typename ... ParTypes>
bool operator()(ParTypes && ...types)
{
return not d_fun(std::forward<ParTypes>(types)...);
}
};
template <typename Fun>
not_fn_<Fun> not_fn(Fun const &fun)
{
return not_fn_<Fun>(fun);
}
using namespace std;
using namespace placeholders;
//main
int main()
{
vector<string> vs {"a", "a", "b"};
string reftext {"b"};
cout <<
count_if(vs.begin(), vs.end(),
bind(not_fn(equal_to<string>()), _1, reftext)) << '\n' <<
count_if(vs.begin(), vs.end(),
not_fn(bind(equal_to<string>(), _1, reftext))) << '\n';
}
//=
|