46 #ifndef LIB_META_FUNCTION_CLOSURE_H 47 #define LIB_META_FUNCTION_CLOSURE_H 83 template<
typename RET,
class FUN,
class TUP>
90 template<
typename RET,
class FUN,
class TUP>
102 template<
typename RET,
class FUN,
class TUP>
104 invoke (FUN& f, TUP & arg)
106 return f (get<0>(arg));
109 template<
typename RET,
class FUN,
class TUP>
111 bind (FUN& f, TUP & arg)
113 return std::bind (f, get<0>(arg));
121 template<
typename RET,
class FUN,
class TUP>
123 invoke (FUN& f, TUP & arg)
125 return f ( get<0>(arg)
130 template<
typename RET,
class FUN,
class TUP>
132 bind (FUN& f, TUP & arg)
134 return std::bind (f, get<0>(arg)
144 template<
typename RET,
class FUN,
class TUP>
146 invoke (FUN& f, TUP & arg)
148 return f ( get<0>(arg)
154 template<
typename RET,
class FUN,
class TUP>
156 bind (FUN& f, TUP & arg)
158 return std::bind (f, get<0>(arg)
169 template<
typename RET,
class FUN,
class TUP>
171 invoke (FUN& f, TUP & arg)
173 return f ( get<0>(arg)
180 template<
typename RET,
class FUN,
class TUP>
182 bind (FUN& f, TUP & arg)
184 return std::bind (f, get<0>(arg)
196 template<
typename RET,
class FUN,
class TUP>
198 invoke (FUN& f, TUP & arg)
200 return f ( get<0>(arg)
208 template<
typename RET,
class FUN,
class TUP>
210 bind (FUN& f, TUP & arg)
212 return std::bind (f, get<0>(arg)
225 template<
typename RET,
class FUN,
class TUP>
227 invoke (FUN& f, TUP & arg)
229 return f ( get<0>(arg)
238 template<
typename RET,
class FUN,
class TUP>
240 bind (FUN& f, TUP & arg)
242 return std::bind (f, get<0>(arg)
256 template<
typename RET,
class FUN,
class TUP>
258 invoke (FUN& f, TUP & arg)
260 return f ( get<0>(arg)
270 template<
typename RET,
class FUN,
class TUP>
272 bind (FUN& f, TUP & arg)
274 return std::bind (f, get<0>(arg)
289 template<
typename RET,
class FUN,
class TUP>
291 invoke (FUN& f, TUP & arg)
293 return f ( get<0>(arg)
304 template<
typename RET,
class FUN,
class TUP>
306 bind (FUN& f, TUP & arg)
308 return std::bind (f, get<0>(arg)
324 template<
typename RET,
class FUN,
class TUP>
326 invoke (FUN& f, TUP & arg)
328 return f ( get<0>(arg)
340 template<
typename RET,
class FUN,
class TUP>
342 bind (FUN& f, TUP & arg)
344 return std::bind (f, get<0>(arg)
366 using std::_Placeholder;
374 template<
typename TYPES,
size_t i=1>
379 template<
typename X,
typename TAIL,
size_t i>
395 using std::tuple_element;
396 using std::tuple_size;
418 template<
typename SRC,
typename TAR,
size_t start>
422 using DestType =
typename std::tuple_element<i, TAR>::type;
430 static constexpr
bool 433 return (start <= idx)
434 and (idx < start + std::tuple_size<SRC>());
439 template<
size_t idx,
bool doPick = PartiallyInitTuple::useArg(
idx)>
444 operator DestType<idx>()
446 return std::get<idx-start> (initArgs);
455 operator DestType<idx>()
457 return DestType<idx>();
476 template<
typename SIG>
482 using BoundFunc = function<Ret()>;
511 template<
typename SIG>
517 function<Ret(void)> closure_;
527 Ret operator() () {
return closure_(); }
530 typedef void argument_type;
551 template<
typename SIG,
typename VAL>
556 typedef typename Args::List ArgsList;
557 typedef typename VAL::List ValList;
562 , ROFFSET = (VAL_CNT < ARG_CNT)? ARG_CNT-VAL_CNT : 0
575 typedef typename func::PlaceholderTuple<LeftReduced>::List TrailingPlaceholders;
576 typedef typename func::PlaceholderTuple<RightReduced>::List LeadingPlaceholders;
590 template<
class SRC,
class TAR,
size_t i>
591 using IdxSelectorL =
typename PartiallyInitTuple<SRC, TAR, 0>::template IndexMapper<i>;
593 template<
class SRC,
class TAR,
size_t i>
594 using IdxSelectorR =
typename PartiallyInitTuple<SRC, TAR, ROFFSET>::template IndexMapper<i>;
610 typedef function<typename FunctionTypedef<Ret,ArgsL>::Sig> LeftReducedFunc;
611 typedef function<typename FunctionTypedef<Ret,ArgsR>::Sig> RightReducedFunc;
622 static LeftReducedFunc
626 return func::Apply<ARG_CNT>::template bind<LeftReducedFunc> (f, params);
637 static RightReducedFunc
641 return func::Apply<ARG_CNT>::template bind<RightReducedFunc> (f, params);
651 namespace _composed {
654 using std::placeholders::_1;
655 using std::placeholders::_2;
656 using std::placeholders::_3;
657 using std::placeholders::_4;
658 using std::placeholders::_5;
659 using std::placeholders::_6;
660 using std::placeholders::_7;
661 using std::placeholders::_8;
662 using std::placeholders::_9;
664 template<
typename RES,
typename F1,
typename F2, u
int n>
667 template<
typename RES,
typename F1,
typename F2>
670 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1)); }
673 template<
typename RES,
typename F1,
typename F2>
676 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1)); }
679 template<
typename RES,
typename F1,
typename F2>
682 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2)); }
685 template<
typename RES,
typename F1,
typename F2>
688 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3)); }
691 template<
typename RES,
typename F1,
typename F2>
694 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4)); }
697 template<
typename RES,
typename F1,
typename F2>
700 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4,_5)); }
703 template<
typename RES,
typename F1,
typename F2>
706 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6)); }
709 template<
typename RES,
typename F1,
typename F2>
712 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7)); }
715 template<
typename RES,
typename F1,
typename F2>
718 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8)); }
721 template<
typename RES,
typename F1,
typename F2>
724 static function<RES> func(F1& f1, F2& f2) {
return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8,_9)); }
736 template<
typename F1,
typename RET>
750 static function<ChainedSig>
751 chain (F1& f1, SigF2& f2)
755 static function<ChainedSig>
756 chain (F1& f1, function<SigF2>& f2)
768 template<
typename SIG,
typename X, u
int pos>
773 typedef typename Args::List ArgsList;
780 typedef typename func::PlaceholderTuple<RemainingFront>::List PlaceholdersBefore;
781 typedef typename func::PlaceholderTuple<RemainingBack,pos+1>::List PlaceholdersBehind;
782 typedef typename Append<
typename Append< PlaceholdersBefore
792 template<
class SRC,
class TAR,
size_t i>
793 using IdxSelector =
typename PartiallyInitTuple<SRC, TAR, pos>::template IndexMapper<i>;
800 typedef function<ReducedSig> ReducedFunc;
806 return func::Apply<ARG_CNT>::template bind<ReducedFunc> (f, params);
814 template<
typename RET,
typename ARG>
821 template<
typename SIG,
typename ARG>
825 typedef typename _Sig<Ret,ARG>::Type Signature;
829 template<
typename SIG1,
typename SIG2>
835 typedef function<Chained> Function;
838 template<
typename SIG>
845 typedef typename _Sig<Ret,Rest>::Type Signature;
846 typedef function<Signature> Function;
849 template<
typename SIG>
856 typedef typename _Sig<Ret,Rest>::Type Signature;
857 typedef function<Signature> Function;
871 template<
typename...ARG>
873 typename _Sig<void,
Types<ARG...>>::Applicator
876 typedef typename _Sig<void,
Types<ARG...>>::Type Signature;
882 template<
typename SIG,
typename...ARG>
885 apply (SIG& f, std::tuple<ARG...>& args)
888 typedef typename _Sig<Ret,
Types<ARG...>>::Type Signature;
897 template<
typename SIG,
typename...ARG>
899 typename _Clo<SIG,
Types<ARG...>>::Type
902 typedef typename _Clo<SIG,
Types<ARG...>>::Type Closure;
903 return Closure (f,args);
908 template<
typename SIG,
typename ARG>
910 typename _PapS<SIG>::Function
913 typedef typename _PapS<SIG>::Arg ArgType;
921 template<
typename SIG,
typename ARG>
923 typename _PapE<SIG>::Function
926 typedef typename _PapE<SIG>::Arg ArgType;
936 template<
typename SIG,
typename TERM>
938 typename _PapE<SIG>::Function
950 template<
typename SIG1,
typename SIG2>
952 typename _Chain<SIG1,SIG2>::Function
955 typedef typename _Chain<SIG1,SIG2>::Ret Ret;
_Clo< SIG, Types< ARG... > >::Type closure(SIG &f, std::tuple< ARG... > &args)
close the given function over all arguments, using the values from the argument tuple.
_PapS< SIG >::Function applyFirst(SIG &f, ARG arg)
close the given function over the first argument
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Implementation namespace for support and library code.
Metaprogramming with tuples-of-types and the std::tuple record.
_PapE< SIG >::Function applyLast(SIG &f, ARG arg)
close the given function over the last argument
Metaprogramming tools for transforming functor types.
_Sig< void, Types< ARG... > >::Applicator tupleApplicator(std::tuple< ARG... > &args)
build a TupleApplicator, which embodies the given argument tuple and can be used to apply them to var...
_PapE< SIG >::Function bindLast(SIG &f, TERM const &arg)
bind the last function argument to an arbitrary term, which especially might be a (nested) binder...
_Chain< SIG1, SIG2 >::Function chained(SIG1 &f1, SIG2 &f2)
build a functor chaining the given functions
_Fun< SIG >::Ret apply(SIG &f, std::tuple< ARG... > &args)
apply the given function to the argument tuple