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