File: predicates.h

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 (108 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//UNARYPRED
    template<typename Type, typename F_PTR = int(*)(int)>
    class PredicateFunction1
    {
        F_PTR d_fun;
        public:
            using argument_type = Type;

            PredicateFunction1(F_PTR const &ptr)
            :
                d_fun(ptr)
            {}

            bool operator()(Type const &t) const
            {
                return d_fun(t);
            }
    };
//=
//BINPRED
    template<typename Type1, typename Type2,
             typename F_PTR = int(*)(Type1 const &t1, Type2 const &t2)>
    class PredicateFunction2
    {
        F_PTR d_fun;
        public:
            using first_argument_type = Type1;
            using second_argument_type = Type2;
            using result_type = bool;

            PredicateFunction2(F_PTR const &ptr)
            :
                d_fun(ptr)
            {}

            bool operator()(Type1 const &t1, Type2 const &t2) const
            {
                return d_fun(t1, t2);
            }
    };
//=
//PREDOBJ1
    template <class Class, typename Type>
    class PredicateObject1
    {
        Class &d_cl;
        bool (Class::*d_member)(Type const &);

        public:
            using argument_type = Type;

            PredicateObject1(Class &cl, bool (Class::*member)(Type const &) =
                                       &Class::operator())
            :
                d_cl(cl),
                d_member(member)
            {}
            PredicateObject1(Class *cl, bool (Class::*member)(Type const &) =
                                    &Class::operator())
            :
                d_cl(*cl),
                d_member(member)
            {}
            bool operator()(Type const &t) const
            {
                return (d_cl.*d_member)(t);
            }
            operator Class() const
            {
                return d_cl;
            }
    };
//=
//PREDOBJ2
    template <class Class, typename Type1, typename Type2 = Type1>
    class PredicateObject2
    {
        Class &d_cl;
        bool (Class::*d_member)(Type1 const &, Type2 const &);
        public:
            using first_argument_type = Type1;
            using second_argument_type = Type2;
            using result_type = bool;

            PredicateObject2(Class &cl,
                    bool (Class::*member)(Type1 const &, Type2 const &) =
                                       &Class::operator())
            :
                d_cl(cl),
                d_member(member)
            {}
            PredicateObject2(Class *cl,
                    bool (Class::*member)(Type1 const &, Type2 const &) =
                                       &Class::operator())
            :
                d_cl(*cl),
                d_member(member)
            {}
            bool operator()(Type1 const &t1, Type2 const &t2) const
            {
                return (d_cl.*d_member)(t1, t2);
            }
            operator Class() const
            {
                return d_cl;
            }
    };
//=