44 using func::applyFirst;
45 using func::applyLast;
48 using func::BindToArgument;
49 using std::make_tuple;
74 template<u
int i, u
int ii>
84 template<u
int i, u
int ii, u
int iii>
91 val1.o_ += val2.o_ + val3.o_;
95 template<u
int i, u
int ii, u
int iii, u
int iv>
103 val1.o_ += val2.o_ + val3.o_ + val4.o_;
107 template<u
int i, u
int ii, u
int iii, u
int iv, u
int v>
116 val1.o_ += val2.o_ + val3.o_ + val4.o_ + val5.o_;
148 check_partialApplication();
149 check_functionalComposition();
150 check_bindToArbitraryParameter();
160 CHECK (6 == (fun13<1,2,3> (_1_, _2_, _3_)).o_ );
163 CHECK ( 1 ==
fun2 (fun11<1> (_1_)) );
164 CHECK ( 3 ==
fun2 (fun12<1,2> (_1_, _2_)) );
165 CHECK ( 6 ==
fun2 (fun13<1,2,3> (_1_, _2_, _3_)) );
166 CHECK (10 ==
fun2 (fun14<1,2,3,4> (_1_, _2_, _3_, _4_)) );
167 CHECK (15 ==
fun2 (fun15<1,2,3,4,5> (_1_, _2_, _3_, _4_, _5_)) );
169 CHECK ( 9 ==
fun2 (fun13<2,3,4> (_2_, _3_, _4_)) );
170 CHECK (18 ==
fun2 (fun13<5,6,7> (_5_, _6_, _7_)) );
171 CHECK (24 ==
fun2 (fun13<9,8,7> (_9_, _8_, _7_)) );
176 check_partialApplication ()
185 typedef function<Sig23> F23;
187 Sig123& f =fun13<1,2,3>;
192 using PH1 = std::_Placeholder<1>;
193 using PH2 = std::_Placeholder<2>;
199 F23 fun_23 = std::bind (f, num18
205 res = fun_23 (_2_,_3_).o_;
213 PartialArg arg(num18, PH1(), PH2());
215 fun_23 = std::bind (f, get<0>(arg)
220 res = fun_23 (_2_,_3_).o_;
234 res = fun_23 (_2_,_3_).o_;
244 fun_23 = func::applyFirst (f,
Num<1>(18));
247 res = fun_23 (_2_,_3_).o_;
253 function<Sig123> func123 (f);
254 fun_23 = func::applyFirst (func123,
Num<1>(19));
255 res = fun_23 (_2_,_3_).o_;
259 F12 fun_12 = func::applyLast(f,
Num<3>(20));
260 res = fun_12 (_1_,_2_).o_;
263 fun_12 = func::applyLast(func123,
Num<3>(21));
264 res = fun_12 (_1_,_2_).o_;
268 fun_12 = func::applyLast( fP,
Num<3>(22));
269 res = fun_12 (_1_,_2_).o_;
273 CHECK (1 == (func::applyLast (fun11<1> , _1_ ) ( ) ).o_);
274 CHECK (1+3 == (func::applyLast (fun12<1,3> , _3_ ) (_1_) ).o_);
275 CHECK (1+3+5 == (func::applyLast (fun13<1,3,5> , _5_ ) (_1_,_3_) ).o_);
276 CHECK (1+3+5+7 == (func::applyLast (fun14<1,3,5,7> , _7_ ) (_1_,_3_,_5_) ).o_);
277 CHECK (1+3+5+7+9 == (func::applyLast (fun15<1,3,5,7,9>, _9_ ) (_1_,_3_,_5_,_7_)).o_);
279 CHECK (9+8+7+6+5 == (func::applyFirst(fun15<9,8,7,6,5>, _9_ ) (_8_,_7_,_6_,_5_)).o_);
280 CHECK ( 8+7+6+5 == (func::applyFirst( fun14<8,7,6,5>, _8_ ) (_7_,_6_,_5_)).o_);
281 CHECK ( 7+6+5 == (func::applyFirst( fun13<7,6,5>, _7_ ) (_6_,_5_)).o_);
282 CHECK ( 6+5 == (func::applyFirst( fun12<6,5>, _6_ ) (_5_)).o_);
283 CHECK ( 5 == (func::applyFirst( fun11<5>, _5_ ) ( )).o_);
295 make_tuple(_3_,_2_,_1_)
299 Num<5> resN5 = fun_54 (_5_,_4_);
300 CHECK (5+4+3+2+1 == resN5.o_);
307 check_functionalComposition ()
316 Sig2 & ff = fun2< Num<1> >;
317 Sig11& f1 = fun11<1>;
318 Sig12& f2 = fun12<1,2>;
319 Sig13& f3 = fun13<1,2,3>;
320 Sig14& f4 = fun14<1,2,3,4>;
321 Sig15& f5 = fun15<1,2,3,4,5>;
323 CHECK (1 == func::chained(f1, ff) (_1_) );
324 CHECK (1+2 == func::chained(f2, ff) (_1_,_2_) );
325 CHECK (1+2+3 == func::chained(f3, ff) (_1_,_2_,_3_) );
326 CHECK (1+2+3+4 == func::chained(f4, ff) (_1_,_2_,_3_,_4_) );
327 CHECK (1+2+3+4+5 == func::chained(f5, ff) (_1_,_2_,_3_,_4_,_5_) );
330 function<Sig15> f5_fun = f5;
331 function<Sig2> ff_fun = ff;
332 CHECK (1+2+3+4+5 == func::chained(f5_fun, ff ) (_1_,_2_,_3_,_4_,_5_) );
333 CHECK (1+2+3+4+5 == func::chained(f5, ff_fun) (_1_,_2_,_3_,_4_,_5_) );
334 CHECK (1+2+3+4+5 == func::chained(f5_fun, ff_fun) (_1_,_2_,_3_,_4_,_5_) );
340 check_bindToArbitraryParameter ()
352 Sig15& f = fun15<1,2,3,4,5>;
353 SigA5& f5 = fun11<5>;
362 CHECK (55+2+3+4+5 == f_bound_1 ( _2_,_3_,_4_,_5_) );
363 CHECK (1+55+3+4+5 == f_bound_2 (_1_, _3_,_4_,_5_) );
364 CHECK (1+2+55+4+5 == f_bound_3 (_1_,_2_, _4_,_5_) );
365 CHECK (1+2+3+55+5 == f_bound_4 (_1_,_2_,_3_, _5_) );
366 CHECK (1+2+3+4+55 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
372 CHECK (1+2+3+4+5 == f_bound_X (_1_,_2_,_3_,_4_,_5_) );
379 f_bound_5 = bindLast (f, bind(f5,
Num<5>(99)));
380 CHECK (1+2+3+4+99 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
382 f_bound_5 = bindLast (f, bind(&f5,
Num<5>(99)));
383 CHECK (1+2+3+4+99 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
385 function<Sig15> asFunctor(f);
386 f_bound_5 = bindLast (asFunctor, bind(f5,
Num<5>(88)));
387 CHECK (1+2+3+4+88 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
392 static long floorIt (
float it) {
return long(floor (it)); }
401 auto fun = std::function{[](
float& f,
int& i,
long l) ->
double {
return f + i + l; }};
405 auto chain = func::chained(f1,
floorIt);
406 auto pappl = func::applyFirst (f1, ff);
412 CHECK (showType<Sig1>() ==
"double (float&, int&, long)"_expect);
413 CHECK (showType<SigC>() ==
"long (float&, int&, long)"_expect);
414 CHECK (showType<SigP>() ==
"double (int&, long)"_expect);
416 CHECK (220 == f1 (ff,ii,33));
417 CHECK (220 == chain(ff,ii,33));
418 CHECK (220 == pappl( ii,33));
425 CHECK ( 97 == f1 (ff,ii,33));
426 CHECK ( 97 == chain(ff,ii,33));
427 CHECK ( 97 == pappl( ii,33));
430 fun = [](
float& f,
int& i,
size_t s) ->
double {
return f - i - s; };
432 CHECK (-13 == f1 (ff,ii,33));
433 CHECK (-13 == chain(ff,ii,33));
434 CHECK (-13 == pappl( ii,33));
A template metaprogramming technique for manipulating collections of types.
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Partial function application and building a complete function closure.
Implementation namespace for support and library code.
Metaprogramming tools for transforming functor types.
Simple test class runner.
A collection of frequently used helper functions to support unit testing.
string showType()
diagnostic type output, including const and similar adornments
Support for writing metaprogramming unit-tests dealing with typelists and flags.