21 using namespace paal::utils;
23 void functors_example() {
32 assert(
id(
"asd") == std::string(
"asd"));
40 assert(retTrue(2, 2.3,
"abc"));
41 assert(!retFalse(2, 2.3,
"abc"));
42 assert(retZero(2, 2.3,
"abc") == 0);
49 std::vector<int> vec{ 1, 2, 3 };
51 assert(vecFun(1) == 2);
54 assert(vecFunWithOffset(1) == 3);
57 void compare_functors() {
90 void comparator_functor() {
91 auto getFirst = [](std::pair<int, int> p) {
return p.first; };
94 assert(!compareFirst(std::make_pair(1, 2), std::make_pair(0, 1)));
98 assert(compareFirstDesc(std::make_pair(1, 2), std::make_pair(0, 1)));
101 void boolean_functors() {
106 assert(!notFun(
true));
107 assert(notFun(
false));
109 assert(!orFun(
false,
false));
110 assert(orFun(
true,
false));
111 assert(orFun(
false,
true));
112 assert(orFun(
true,
true));
114 assert(!andFun(
false,
false));
115 assert(!andFun(
true,
false));
116 assert(!andFun(
false,
true));
117 assert(andFun(
true,
true));
120 void lift_operator_functor() {
121 auto oper = [](
int a,
int b) {
return a + b > 0; };
127 assert(f(1, 2, 41243.2,
"dada"));
130 void boolean_functors_on_functors() {
136 assert(trueFunctor(1.2,
"xada", 3));
141 assert(!falseFunctor(1.2,
"xada", 3));
146 assert(trueFunctor(1.2,
"xada", 3));
151 assert(!falseFunctor(1.2,
"xada", 3));
156 assert(trueFunctor(1.2,
"xada", 3));
163 comparator_functor();
165 lift_operator_functor();
166 boolean_functors_on_functors();
auto make_or_functor(FunctorLeft left, FunctorRight right)
make for or_functor
Functor returns always the same number. The number has to be known at compile time.
auto make_xor_functor(FunctorLeft left, FunctorRight right)
make for Xor
auto make_functor_to_comparator(Functor functor, Compare compare=Compare())
make for functor to comparator
This file contains set of simple useful functors or functor adapters.
auto make_not_functor(Functor functor)
make for Not
auto make_array_to_functor(const Array &a, int offset=0)
make function for array_to_functor
auto make_lift_binary_operator_functor(FunctorLeft left, FunctorRight right, Operator op)
make function for lift_binary_operator_functor
functor returns its argument
auto make_and_functor(FunctorLeft left, FunctorRight right)
make and_functor