File: notfn.cc

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (45 lines) | stat: -rw-r--r-- 847 bytes parent folder | download | duplicates (5)
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';
}
//=