35 using func::applyFirst;
36 using func::applyLast;
39 using func::BindToArgument;
40 using std::make_tuple;
65 template<u
int i, u
int ii>
75 template<u
int i, u
int ii, u
int iii>
82 val1.o_ += val2.o_ + val3.o_;
86 template<u
int i, u
int ii, u
int iii, u
int iv>
94 val1.o_ += val2.o_ + val3.o_ + val4.o_;
98 template<u
int i, u
int ii, u
int iii, u
int iv, u
int v>
107 val1.o_ += val2.o_ + val3.o_ + val4.o_ + val5.o_;
139 check_partialApplication();
140 check_functionalComposition();
141 check_bindToArbitraryParameter();
151 CHECK (6 == (fun13<1,2,3> (_1_, _2_, _3_)).o_ );
154 CHECK ( 1 ==
fun2 (fun11<1> (_1_)) );
155 CHECK ( 3 ==
fun2 (fun12<1,2> (_1_, _2_)) );
156 CHECK ( 6 ==
fun2 (fun13<1,2,3> (_1_, _2_, _3_)) );
157 CHECK (10 ==
fun2 (fun14<1,2,3,4> (_1_, _2_, _3_, _4_)) );
158 CHECK (15 ==
fun2 (fun15<1,2,3,4,5> (_1_, _2_, _3_, _4_, _5_)) );
160 CHECK ( 9 ==
fun2 (fun13<2,3,4> (_2_, _3_, _4_)) );
161 CHECK (18 ==
fun2 (fun13<5,6,7> (_5_, _6_, _7_)) );
162 CHECK (24 ==
fun2 (fun13<9,8,7> (_9_, _8_, _7_)) );
167 check_partialApplication ()
176 typedef function<Sig23> F23;
178 Sig123& f =fun13<1,2,3>;
183 using PH1 = std::_Placeholder<1>;
184 using PH2 = std::_Placeholder<2>;
190 F23 fun_23 = std::bind (f, num18
196 res = fun_23 (_2_,_3_).o_;
204 PartialArg arg(num18, PH1(), PH2());
206 fun_23 = std::bind (f, get<0>(arg)
211 res = fun_23 (_2_,_3_).o_;
225 res = fun_23 (_2_,_3_).o_;
235 fun_23 = func::applyFirst (f,
Num<1>(18));
238 res = fun_23 (_2_,_3_).o_;
244 function<Sig123> func123 (f);
245 fun_23 = func::applyFirst (func123,
Num<1>(19));
246 res = fun_23 (_2_,_3_).o_;
250 F12 fun_12 = func::applyLast(f,
Num<3>(20));
251 res = fun_12 (_1_,_2_).o_;
254 fun_12 = func::applyLast(func123,
Num<3>(21));
255 res = fun_12 (_1_,_2_).o_;
259 fun_12 = func::applyLast( fP,
Num<3>(22));
260 res = fun_12 (_1_,_2_).o_;
264 CHECK (1 == (func::applyLast (fun11<1> , _1_ ) ( ) ).o_);
265 CHECK (1+3 == (func::applyLast (fun12<1,3> , _3_ ) (_1_) ).o_);
266 CHECK (1+3+5 == (func::applyLast (fun13<1,3,5> , _5_ ) (_1_,_3_) ).o_);
267 CHECK (1+3+5+7 == (func::applyLast (fun14<1,3,5,7> , _7_ ) (_1_,_3_,_5_) ).o_);
268 CHECK (1+3+5+7+9 == (func::applyLast (fun15<1,3,5,7,9>, _9_ ) (_1_,_3_,_5_,_7_)).o_);
270 CHECK (9+8+7+6+5 == (func::applyFirst(fun15<9,8,7,6,5>, _9_ ) (_8_,_7_,_6_,_5_)).o_);
271 CHECK ( 8+7+6+5 == (func::applyFirst( fun14<8,7,6,5>, _8_ ) (_7_,_6_,_5_)).o_);
272 CHECK ( 7+6+5 == (func::applyFirst( fun13<7,6,5>, _7_ ) (_6_,_5_)).o_);
273 CHECK ( 6+5 == (func::applyFirst( fun12<6,5>, _6_ ) (_5_)).o_);
274 CHECK ( 5 == (func::applyFirst( fun11<5>, _5_ ) ( )).o_);
286 make_tuple(_3_,_2_,_1_)
290 Num<5> resN5 = fun_54 (_5_,_4_);
291 CHECK (5+4+3+2+1 == resN5.o_);
298 check_functionalComposition ()
307 Sig2 & ff = fun2< Num<1> >;
308 Sig11& f1 = fun11<1>;
309 Sig12& f2 = fun12<1,2>;
310 Sig13& f3 = fun13<1,2,3>;
311 Sig14& f4 = fun14<1,2,3,4>;
312 Sig15& f5 = fun15<1,2,3,4,5>;
314 CHECK (1 == func::chained(f1, ff) (_1_) );
315 CHECK (1+2 == func::chained(f2, ff) (_1_,_2_) );
316 CHECK (1+2+3 == func::chained(f3, ff) (_1_,_2_,_3_) );
317 CHECK (1+2+3+4 == func::chained(f4, ff) (_1_,_2_,_3_,_4_) );
318 CHECK (1+2+3+4+5 == func::chained(f5, ff) (_1_,_2_,_3_,_4_,_5_) );
321 function<Sig15> f5_fun = f5;
322 function<Sig2> ff_fun = ff;
323 CHECK (1+2+3+4+5 == func::chained(f5_fun, ff ) (_1_,_2_,_3_,_4_,_5_) );
324 CHECK (1+2+3+4+5 == func::chained(f5, ff_fun) (_1_,_2_,_3_,_4_,_5_) );
325 CHECK (1+2+3+4+5 == func::chained(f5_fun, ff_fun) (_1_,_2_,_3_,_4_,_5_) );
331 check_bindToArbitraryParameter ()
343 Sig15& f = fun15<1,2,3,4,5>;
344 SigA5& f5 = fun11<5>;
353 CHECK (55+2+3+4+5 == f_bound_1 ( _2_,_3_,_4_,_5_) );
354 CHECK (1+55+3+4+5 == f_bound_2 (_1_, _3_,_4_,_5_) );
355 CHECK (1+2+55+4+5 == f_bound_3 (_1_,_2_, _4_,_5_) );
356 CHECK (1+2+3+55+5 == f_bound_4 (_1_,_2_,_3_, _5_) );
357 CHECK (1+2+3+4+55 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
363 CHECK (1+2+3+4+5 == f_bound_X (_1_,_2_,_3_,_4_,_5_) );
370 f_bound_5 = bindLast (f, bind(f5,
Num<5>(99)));
371 CHECK (1+2+3+4+99 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
373 f_bound_5 = bindLast (f, bind(&f5,
Num<5>(99)));
374 CHECK (1+2+3+4+99 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
376 function<Sig15> asFunctor(f);
377 f_bound_5 = bindLast (asFunctor, bind(f5,
Num<5>(88)));
378 CHECK (1+2+3+4+88 == f_bound_5 (_1_,_2_,_3_,_4_ ) );
383 static long floorIt (
float it) {
return long(floor (it)); }
392 auto fun = std::function{[](
float& f,
int& i,
long l) ->
double {
return f + i + l; }};
396 auto chain = func::chained(f1,
floorIt);
397 auto pappl = func::applyFirst (f1, ff);
403 CHECK (showType<Sig1>() ==
"double (float&, int&, long)"_expect);
404 CHECK (showType<SigC>() ==
"long (float&, int&, long)"_expect);
405 CHECK (showType<SigP>() ==
"double (int&, long)"_expect);
407 CHECK (220 == f1 (ff,ii,33));
408 CHECK (220 == chain(ff,ii,33));
409 CHECK (220 == pappl( ii,33));
416 CHECK ( 97 == f1 (ff,ii,33));
417 CHECK ( 97 == chain(ff,ii,33));
418 CHECK ( 97 == pappl( ii,33));
421 fun = [](
float& f,
int& i,
size_t s) ->
double {
return f - i - s; };
423 CHECK (-13 == f1 (ff,ii,33));
424 CHECK (-13 == chain(ff,ii,33));
425 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.
Simplistic 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.