Debian Codegraph @

yo/concrete/examples/predicates.h

raw
1 //UNARYPRED
2 template<typename Type, typename F_PTR = int(*)(int)>
3 class PredicateFunction1
4 {
5 F_PTR d_fun;
6 public:
7 using argument_type = Type;
8
9 PredicateFunction1(F_PTR const &ptr)
10 :
11 d_fun(ptr)
12 {}
13
14 bool operator()(Type const &t) const
15 {
16 return d_fun(t);
17 }
18 };
19 //=
20 //BINPRED
21 template<typename Type1, typename Type2,
22 typename F_PTR = int(*)(Type1 const &t1, Type2 const &t2)>
23 class PredicateFunction2
24 {
25 F_PTR d_fun;
26 public:
27 using first_argument_type = Type1;
28 using second_argument_type = Type2;
29 using result_type = bool;
30
31 PredicateFunction2(F_PTR const &ptr)
32 :
33 d_fun(ptr)
34 {}
35
36 bool operator()(Type1 const &t1, Type2 const &t2) const
37 {
38 return d_fun(t1, t2);
39 }
40 };
41 //=
42 //PREDOBJ1
43 template <class Class, typename Type>
44 class PredicateObject1
45 {
46 Class &d_cl;
47 bool (Class::*d_member)(Type const &);
48
49 public:
50 using argument_type = Type;
51
52 PredicateObject1(Class &cl, bool (Class::*member)(Type const &) =
53 &Class::operator())
54 :
55 d_cl(cl),
56 d_member(member)
57 {}
58 PredicateObject1(Class *cl, bool (Class::*member)(Type const &) =
59 &Class::operator())
60 :
61 d_cl(*cl),
62 d_member(member)
63 {}
64 bool operator()(Type const &t) const
65 {
66 return (d_cl.*d_member)(t);
67 }
68 operator Class() const
69 {
70 return d_cl;
71 }
72 };
73 //=
74 //PREDOBJ2
75 template <class Class, typename Type1, typename Type2 = Type1>
76 class PredicateObject2
77 {
78 Class &d_cl;
79 bool (Class::*d_member)(Type1 const &, Type2 const &);
80 public:
81 using first_argument_type = Type1;
82 using second_argument_type = Type2;
83 using result_type = bool;
84
85 PredicateObject2(Class &cl,
86 bool (Class::*member)(Type1 const &, Type2 const &) =
87 &Class::operator())
88 :
89 d_cl(cl),
90 d_member(member)
91 {}
92 PredicateObject2(Class *cl,
93 bool (Class::*member)(Type1 const &, Type2 const &) =
94 &Class::operator())
95 :
96 d_cl(*cl),
97 d_member(member)
98 {}
99 bool operator()(Type1 const &t1, Type2 const &t2) const
100 {
101 return (d_cl.*d_member)(t1, t2);
102 }
103 operator Class() const
104 {
105 return d_cl;
106 }
107 };
108 //=