From d13d461a9c72b21ec316155e6805006cb568bdb5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 3 Jul 2009 14:31:52 +0200 Subject: [PATCH] revamp namespace func. Finish excursion on function handling --- src/lib/meta/function-closure.hpp | 616 +++++++++---------- src/proc/control/command-closure.hpp | 2 +- tests/40components.tests | 2 +- tests/lib/meta/function-closure-test.cpp | 83 +-- tests/lib/meta/function-composition-test.cpp | 22 +- 5 files changed, 348 insertions(+), 377 deletions(-) diff --git a/src/lib/meta/function-closure.hpp b/src/lib/meta/function-closure.hpp index 10dcab8dd..74149ab40 100644 --- a/src/lib/meta/function-closure.hpp +++ b/src/lib/meta/function-closure.hpp @@ -25,7 +25,8 @@ ** Partial function application and building a complete function closure. ** This is a small addendum to (and thin wrapper for) tr1/functional, supporting ** the case when a function should be closed over (partially or all) arguments, - ** where especially the parameter values to close on are provided as a tuple. + ** where especially the parameter values to close on are provided as a tuple. + ** Additionally, we allow for composing (chaining) of two functions. ** ** Because we have to deal with arbitrary functions and arbitrary parameter types, ** we need a lot of repetitive code to "catch" functions from zero to nine arguments. @@ -55,15 +56,14 @@ namespace lumiera { namespace typelist{ - +namespace func { + using std::tr1::function; -//using std::tr1::bind; -//using std::tr1::placeholders::_1; - - namespace func { ///< helpers for binding and applying a function to an argument tuple + + namespace { // helpers for binding and applying a function to an argument tuple using tuple::element; @@ -96,7 +96,7 @@ namespace typelist{ /** * this Helper with repetitive specialisations for up to nine arguments * is used either to apply a function to arguments given as a tuple, or - * to create the actual closure (functor) over all function arguments. + * to create the actual closure (functor) over all function arguments. */ template struct Apply; @@ -419,9 +419,7 @@ namespace typelist{ }; - - - } // (END) impl-namespace (func) + } // (END) impl-namespace @@ -450,232 +448,15 @@ namespace typelist{ : params_(args) { } - BoundFunc bind (SIG& f) { return func::Apply::template bind (f, params_); } - BoundFunc bind (function const& f) { return func::Apply::template bind (f, params_); } + BoundFunc bind (SIG& f) { return Apply::template bind (f, params_); } + BoundFunc bind (function const& f) { return Apply::template bind (f, params_); } - Ret operator() (SIG& f) { return func::Apply::template invoke (f, params_); } - Ret operator() (function& f) { return func::Apply::template invoke (f, params_); } + Ret operator() (SIG& f) { return Apply::template invoke (f, params_); } + Ret operator() (function& f) { return Apply::template invoke (f, params_); } }; - /** - * Partial function application - * Takes a function and a value tuple, - * using the latter to close function arguments - * either from the front (left) or aligned to the end - * of the function argument list. Result is a "reduced" function, - * expecting only the remaining "un-closed" arguments at invocation. - */ - template - class PApply - { - typedef typename func::_Fun::Args Args; - typedef typename func::_Fun::Ret Ret; - typedef typename Args::List ArgsList; - typedef typename VAL::List ValList; - - enum { ARG_CNT = count::value - , VAL_CNT = count ::value - , ROFFSET = (VAL_CNT < ARG_CNT)? ARG_CNT-VAL_CNT : 0 - }; - - - // create list of the *remaining* arguments, after applying the ValList - typedef typename Splice::Back LeftReduced; - typedef typename Splice::Front RightReduced; - - // build a list, where each of the *remaining* arguments is replaced by a placeholder marker - typedef typename func::PlaceholderTuple::PlaceholderSeq::List LeftPlaceholders; - typedef typename func::PlaceholderTuple::PlaceholderSeq::List RightPlaceholders; - - // ... and splice these placeholders on top of the original argument type list, - // thus retaining the types to be closed, but setting a placeholder for each remaining argument - typedef typename Splice::List LeftReplaced; - typedef typename Splice::List RightReplaced; - - typedef Tuple TupleL; - typedef Tuple TupleR; - - typedef typename Tuple::Type ArgsL; - typedef typename Tuple::Type ArgsR; - - // create a "builder" helper, which accepts exactly the value tuple elements - // and puts them at the right location, while default-constructing the remaining - // (=placeholder)-arguments. Using this builder helper, we can finally set up - // the argument tuples (Left/RightReplacedArgs) used for the tr1::bind call - typedef tuple::BuildTuple BuildL; - typedef tuple::BuildTuple BuildR; - - - public: - typedef function::Sig> LeftReducedFunc; - typedef function::Sig> RightReducedFunc; - - - /** Contains the argument values, starting from left. - * Any remaining positions are occupied by binding placeholders */ - struct LeftReplacedArgs - : TupleL - { - LeftReplacedArgs (Tuple const& arg) - : TupleL ( BuildL::create(arg)) - { } - }; - - /** Contains the argument values, aligned to the end of the function argument list. - * Any remaining positions before are occupied by binding placeholders */ - struct RightReplacedArgs - : TupleR - { - RightReplacedArgs (Tuple const& arg) - : TupleR ( BuildR::create(arg)) - { } - }; - - - /** do a partial function application, closing the first arguments - * f(a,b,c)->res + (a,b) yields f(c)->res - * - * @param f function, function pointer or functor - * @param arg value tuple, used to close function arguments starting from left - * @return new function object, holding copies of the values and using them at the - * closed arguments; on invocation, only the remaining arguments need to be supplied. - */ - static LeftReducedFunc - bindFront (SIG& f, Tuple const& arg) - { - LeftReplacedArgs params (arg); - return func::Apply::template bind (f, params.tupleCast()); - } - - /** do a partial function application, closing the last arguments - * f(a,b,c)->res + (b,c) yields f(a)->res - * - * @param f function, function pointer or functor - * @param arg value tuple, used to close function arguments starting from right - * @return new function object, holding copies of the values and using them at the - * closed arguments; on invocation, only the remaining arguments need to be supplied. - */ - static RightReducedFunc - bindBack (SIG& f, Tuple const& arg) - { - RightReplacedArgs params (arg); - return func::Apply::template bind (f, params.tupleCast()); - } - }; - - - - namespace _cmp { - using std::tr1::bind; - using std::tr1::placeholders::_1; - using std::tr1::placeholders::_2; - using std::tr1::placeholders::_3; - using std::tr1::placeholders::_4; - using std::tr1::placeholders::_5; - using std::tr1::placeholders::_6; - using std::tr1::placeholders::_7; - using std::tr1::placeholders::_8; - using std::tr1::placeholders::_9; - - template - struct BuildComposed; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8)); } - }; - - template - struct BuildComposed - { - static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8,_9)); } - }; - - } - - /** - * Functional composition. Create a functor, which - * on invocation will execute two functions chained, - * i.e. fed the result of invoking the first function - * as argument into the second function. - */ - template - class FunctionComposition - { - typedef typename func::_Fun::Args Args; - typedef typename func::_Fun::Ret Ret1; - - typedef Types ArgsF2; - typedef typename FunctionTypedef::Sig SigF2; - typedef typename FunctionTypedef::Sig ChainedSig; - - - enum { ARG_CNT = count::value }; - - - public: - static function - chain (SIG1& f1, SigF2& f2) - { - return _cmp::BuildComposed::func (f1,f2); - } - - }; - - - - /** * Closing a function over its arguments. * This is a small usage example or spin-off, @@ -707,11 +488,212 @@ namespace typelist{ - namespace func { // ...some convenience shortcuts - - - // helpers for specifying types in function declarations.... + /** + * Partial function application + * Takes a function and a value tuple, + * using the latter to close function arguments + * either from the front (left) or aligned to the end + * of the function argument list. Result is a "reduced" function, + * expecting only the remaining "un-closed" arguments at invocation. + */ + template + class PApply + { + typedef typename _Fun::Args Args; + typedef typename _Fun::Ret Ret; + typedef typename Args::List ArgsList; + typedef typename VAL::List ValList; + + enum { ARG_CNT = count::value + , VAL_CNT = count ::value + , ROFFSET = (VAL_CNT < ARG_CNT)? ARG_CNT-VAL_CNT : 0 + }; + + + // create list of the *remaining* arguments, after applying the ValList + typedef typename Splice::Back LeftReduced; + typedef typename Splice::Front RightReduced; + + // build a list, where each of the *remaining* arguments is replaced by a placeholder marker + typedef typename func::PlaceholderTuple::PlaceholderSeq::List LeftPlaceholders; + typedef typename func::PlaceholderTuple::PlaceholderSeq::List RightPlaceholders; + + // ... and splice these placeholders on top of the original argument type list, + // thus retaining the types to be closed, but setting a placeholder for each remaining argument + typedef typename Splice::List LeftReplaced; + typedef typename Splice::List RightReplaced; + + typedef typename Tuple::Type ArgsL; + typedef typename Tuple::Type ArgsR; + + // create a "builder" helper, which accepts exactly the value tuple elements + // and puts them at the right location, while default-constructing the remaining + // (=placeholder)-arguments. Using this builder helper, we can finally set up + // the argument tuples (Left/RightReplacedArgs) used for the tr1::bind call + typedef tuple::BuildTuple BuildL; + typedef tuple::BuildTuple BuildR; + + /** Contains the argument values, starting from left. + * Any remaining positions are occupied by binding placeholders */ + typedef typename Tuple::TupleType LeftReplacedArgs; + + /** Contains the argument values, aligned to the end of the function argument list. + * Any remaining positions before are occupied by binding placeholders */ + typedef typename Tuple::TupleType RightReplacedArgs; + + + public: + typedef function::Sig> LeftReducedFunc; + typedef function::Sig> RightReducedFunc; + + + /** do a partial function application, closing the first arguments + * f(a,b,c)->res + (a,b) yields f(c)->res + * + * @param f function, function pointer or functor + * @param arg value tuple, used to close function arguments starting from left + * @return new function object, holding copies of the values and using them at the + * closed arguments; on invocation, only the remaining arguments need to be supplied. + */ + static LeftReducedFunc + bindFront (SIG& f, Tuple const& arg) + { + LeftReplacedArgs params (BuildL::create(arg)); + return func::Apply::template bind (f, params); + } + + /** do a partial function application, closing the last arguments + * f(a,b,c)->res + (b,c) yields f(a)->res + * + * @param f function, function pointer or functor + * @param arg value tuple, used to close function arguments starting from right + * @return new function object, holding copies of the values and using them at the + * closed arguments; on invocation, only the remaining arguments need to be supplied. + */ + static RightReducedFunc + bindBack (SIG& f, Tuple const& arg) + { + RightReplacedArgs params (BuildR::create(arg)); + return func::Apply::template bind (f, params); + } + }; + + + + + + + + namespace _composed { // repetitive impl.code for function composition + using std::tr1::bind; + using std::tr1::placeholders::_1; + using std::tr1::placeholders::_2; + using std::tr1::placeholders::_3; + using std::tr1::placeholders::_4; + using std::tr1::placeholders::_5; + using std::tr1::placeholders::_6; + using std::tr1::placeholders::_7; + using std::tr1::placeholders::_8; + using std::tr1::placeholders::_9; + + template + struct Build; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8)); } + }; + + template + struct Build + { + static function func(F1& f1, F2& f2) { return bind (f2, bind (f1,_1,_2,_3,_4,_5,_6,_7,_8,_9)); } + }; + } // (End) impl namespace (_composed) + + + + /** + * Functional composition. Create a functor, which + * on invocation will execute two functions chained, + * i.e. fed the result of invoking the first function + * as argument into the second function. + */ + template + class FunctionComposition + { + typedef typename func::_Fun::Args Args; + typedef typename func::_Fun::Ret Ret1; + + typedef Types ArgsF2; + typedef typename FunctionTypedef::Sig SigF2; + typedef typename FunctionTypedef::Sig ChainedSig; + + enum { ARG_CNT = count::value }; + + + public: + static function + chain (SIG1& f1, SigF2& f2) + { + return _composed::Build::func (f1,f2); + } + }; + + + + namespace { // ...helpers for specifying types in function declarations.... + template struct _Sig { @@ -730,8 +712,8 @@ namespace typelist{ template struct _Chain { - typedef typename func::_Fun::Args Args; - typedef typename func::_Fun::Ret Ret; + typedef typename _Fun::Args Args; + typedef typename _Fun::Ret Ret; typedef typename FunctionTypedef::Sig Chained; typedef function Function; }; @@ -758,87 +740,87 @@ namespace typelist{ typedef function Function; }; - - - - /* ========== function-style interface ============= */ - - /** build a TupleApplicator, which embodies the given - * argument tuple and can be used to apply various - * functions to them. - */ - template - typename _Sig::Applicator - tupleApplicator (Tuple& args) - { - typedef typename _Sig::Type Signature; - return TupleApplicator (args); - } - - - /** apply the given function to the argument tuple */ - template - typename _Fun::Ret - apply (SIG& f, Tuple& args) - { - typedef typename _Fun::Ret Ret; // - typedef typename _Sig::Type Signature; // Note: deliberately re-building the Signature Type - return TupleApplicator (args) (f); // in order to get better error messages here - } - - /** close the given function over all arguments, - * using the values from the argument tuple. - * @return a closure object, which can be - * invoked later to yield the - * function result. */ - template - typename _Clo::Type - closure (SIG& f, Tuple& args) - { - typedef typename _Fun::Ret Ret; - typedef typename _Sig::Type Signature; - typedef typename _Clo::Type Closure; - return Closure (f,args); - } - - - /** close the given function over the first argument */ - template - typename _PapS::Function - applyFirst (SIG& f, ARG arg) - { - typedef typename _PapS::Arg ArgType; - typedef Types ArgTypeSeq; - typedef Tuple ArgTuple; - ArgTuple val(arg); - return PApply::bindFront (f, val); - } - - /** close the given function over the last argument */ - template - typename _PapE::Function - applyLast (SIG& f, ARG arg) - { - typedef typename _PapE::Arg ArgType; - typedef Types ArgTypeSeq; - typedef Tuple ArgTuple; - ArgTuple val(arg); - return PApply::bindBack (f, val); - } - - - /** build a functor chaining the given functions */ - template - typename _Chain::Function - chained (SIG1& f1, SIG2& f2) - { - typedef typename _Chain::Ret Ret; - return FunctionComposition::chain (f1, f2); - } - - } // (END) namespace func + } // (End) argument type shortcuts -}} // namespace lumiera::typelist + + /* ========== function-style interface ============= */ + + /** build a TupleApplicator, which embodies the given + * argument tuple and can be used to apply various + * functions to them. + */ + template + typename _Sig::Applicator + tupleApplicator (Tuple& args) + { + typedef typename _Sig::Type Signature; + return TupleApplicator (args); + } + + + /** apply the given function to the argument tuple */ + template + typename _Fun::Ret + apply (SIG& f, Tuple& args) + { + typedef typename _Fun::Ret Ret; // + typedef typename _Sig::Type Signature; // Note: deliberately re-building the Signature Type + return TupleApplicator (args) (f); // in order to get better error messages here + } + + /** close the given function over all arguments, + * using the values from the argument tuple. + * @return a closure object, which can be + * invoked later to yield the + * function result. */ + template + typename _Clo::Type + closure (SIG& f, Tuple& args) + { + typedef typename _Fun::Ret Ret; + typedef typename _Sig::Type Signature; + typedef typename _Clo::Type Closure; + return Closure (f,args); + } + + + /** close the given function over the first argument */ + template + typename _PapS::Function + applyFirst (SIG& f, ARG arg) + { + typedef typename _PapS::Arg ArgType; + typedef Types ArgTypeSeq; + typedef Tuple ArgTuple; + ArgTuple val(arg); + return PApply::bindFront (f, val); + } + + /** close the given function over the last argument */ + template + typename _PapE::Function + applyLast (SIG& f, ARG arg) + { + typedef typename _PapE::Arg ArgType; + typedef Types ArgTypeSeq; + typedef Tuple ArgTuple; + ArgTuple val(arg); + return PApply::bindBack (f, val); + } + + + /** build a functor chaining the given functions */ + template + typename _Chain::Function + chained (SIG1& f1, SIG2& f2) + { + typedef typename _Chain::Ret Ret; + return FunctionComposition::chain (f1, f2); + } + + + +}}} // namespace lumiera::typelist::func #endif diff --git a/src/proc/control/command-closure.hpp b/src/proc/control/command-closure.hpp index f309d0aef..ff2dc3ec6 100644 --- a/src/proc/control/command-closure.hpp +++ b/src/proc/control/command-closure.hpp @@ -67,7 +67,7 @@ namespace control { using lumiera::typelist::FunctionSignature; using lumiera::typelist::Tuple; using lumiera::typelist::BuildTupleAccessor; - using lumiera::typelist::TupleApplicator; + using lumiera::typelist::func::TupleApplicator; using lumiera::typelist::FunErasure; using lumiera::typelist::StoreFunction; diff --git a/tests/40components.tests b/tests/40components.tests index f333d87ae..a04bcd63c 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -234,7 +234,7 @@ out: dtor ~TargetObj\(12\) successful END -TEST "closing function over its arguments" FunctionClosure_test <-<2>-<3>- out: List2 :-<5>-<6>-<7>- out: Args :-<5>-<9>- diff --git a/tests/lib/meta/function-closure-test.cpp b/tests/lib/meta/function-closure-test.cpp index 2def0fde4..faa998fae 100644 --- a/tests/lib/meta/function-closure-test.cpp +++ b/tests/lib/meta/function-closure-test.cpp @@ -54,7 +54,7 @@ using std::endl; namespace lumiera { namespace typelist{ -namespace test { +namespace test { namespace { // test data @@ -87,12 +87,17 @@ namespace test { int fun3 (int i1, int i2, int i3) { return i1+i2+i3; } } // (End) test data - - - - - - + + + + + using func::Apply; + using func::TupleApplicator; + using func::FunctionClosure; + using func::closure; + using func::apply; + + /************************************************************************* * @test building a function closure for a given function or functor, * while arguments are passed in as tuple @@ -166,20 +171,20 @@ namespace test { DUMPVAL (tup2); DUMPVAL (tup3); - ASSERT (-1 == func::Apply<0>::invoke (fun0, tup0) ); - ASSERT (11 == func::Apply<1>::invoke (fun1, tup1) ); - ASSERT (11+12 == func::Apply<2>::invoke (fun2, tup2) ); - ASSERT (11+12+13 == func::Apply<3>::invoke (fun3, tup3) ); + ASSERT (-1 == Apply<0>::invoke (fun0, tup0) ); + ASSERT (11 == Apply<1>::invoke (fun1, tup1) ); + ASSERT (11+12 == Apply<2>::invoke (fun2, tup2) ); + ASSERT (11+12+13 == Apply<3>::invoke (fun3, tup3) ); ASSERT (-1 == TupleApplicator (tup0) (fun0) ); ASSERT (11 == TupleApplicator (tup1) (fun1) ); ASSERT (11+12 == TupleApplicator (tup2) (fun2) ); ASSERT (11+12+13 == TupleApplicator (tup3) (fun3) ); - ASSERT (-1 == func::apply(fun0, tup0) ); - ASSERT (11 == func::apply(fun1, tup1) ); - ASSERT (11+12 == func::apply(fun2, tup2) ); - ASSERT (11+12+13 == func::apply(fun3, tup3) ); + ASSERT (-1 == apply(fun0, tup0) ); + ASSERT (11 == apply(fun1, tup1) ); + ASSERT (11+12 == apply(fun2, tup2) ); + ASSERT (11+12+13 == apply(fun3, tup3) ); } @@ -196,20 +201,20 @@ namespace test { function functor2 (fun2); function functor3 (fun3); - ASSERT (-1 == func::Apply<0>::invoke (functor0, tup0) ); - ASSERT (11 == func::Apply<1>::invoke (functor1, tup1) ); - ASSERT (11+12 == func::Apply<2>::invoke (functor2, tup2) ); - ASSERT (11+12+13 == func::Apply<3>::invoke (functor3, tup3) ); + ASSERT (-1 == Apply<0>::invoke (functor0, tup0) ); + ASSERT (11 == Apply<1>::invoke (functor1, tup1) ); + ASSERT (11+12 == Apply<2>::invoke (functor2, tup2) ); + ASSERT (11+12+13 == Apply<3>::invoke (functor3, tup3) ); ASSERT (-1 == TupleApplicator (tup0) (functor0) ); ASSERT (11 == TupleApplicator (tup1) (functor1) ); ASSERT (11+12 == TupleApplicator (tup2) (functor2) ); ASSERT (11+12+13 == TupleApplicator (tup3) (functor3) ); - ASSERT (-1 == func::apply(functor0, tup0) ); - ASSERT (11 == func::apply(functor1, tup1) ); - ASSERT (11+12 == func::apply(functor2, tup2) ); - ASSERT (11+12+13 == func::apply(functor3, tup3) ); + ASSERT (-1 == apply(functor0, tup0) ); + ASSERT (11 == apply(functor1, tup1) ); + ASSERT (11+12 == apply(functor2, tup2) ); + ASSERT (11+12+13 == apply(functor3, tup3) ); } @@ -226,10 +231,10 @@ namespace test { typedef function BoundFun; - BoundFun functor0 = func::Apply<0>::bind (fun0, tup0); - BoundFun functor1 = func::Apply<1>::bind (fun1, tup1); - BoundFun functor2 = func::Apply<2>::bind (fun2, tup3); - BoundFun functor3 = func::Apply<3>::bind (fun3, tup3); + BoundFun functor0 = Apply<0>::bind (fun0, tup0); + BoundFun functor1 = Apply<1>::bind (fun1, tup1); + BoundFun functor2 = Apply<2>::bind (fun2, tup3); + BoundFun functor3 = Apply<3>::bind (fun3, tup3); ASSERT (-1 == functor0() ); ASSERT (11 == functor1() ); @@ -263,10 +268,10 @@ namespace test { typedef function BoundFun; - BoundFun functor0 = func::Apply<0>::bind (unbound_functor0, tup0); - BoundFun functor1 = func::Apply<1>::bind (unbound_functor1, tup1); - BoundFun functor2 = func::Apply<2>::bind (unbound_functor2, tup3); - BoundFun functor3 = func::Apply<3>::bind (unbound_functor3, tup3); + BoundFun functor0 = Apply<0>::bind (unbound_functor0, tup0); + BoundFun functor1 = Apply<1>::bind (unbound_functor1, tup1); + BoundFun functor2 = Apply<2>::bind (unbound_functor2, tup3); + BoundFun functor3 = Apply<3>::bind (unbound_functor3, tup3); ASSERT (-1 == functor0() ); ASSERT (11 == functor1() ); @@ -319,15 +324,15 @@ namespace test { ASSERT (11+12 == clo2() ); ASSERT (11+12+13 == clo3() ); - ASSERT (-1 == func::closure(fun0,tup0) () ); - ASSERT (11 == func::closure(fun1,tup1) () ); - ASSERT (11+12 == func::closure(fun2,tup2) () ); - ASSERT (11+12+13 == func::closure(fun3,tup3) () ); + ASSERT (-1 == closure(fun0,tup0) () ); + ASSERT (11 == closure(fun1,tup1) () ); + ASSERT (11+12 == closure(fun2,tup2) () ); + ASSERT (11+12+13 == closure(fun3,tup3) () ); - ASSERT (-1 == func::closure(unbound_functor0,tup0) () ); - ASSERT (11 == func::closure(unbound_functor1,tup1) () ); - ASSERT (11+12 == func::closure(unbound_functor2,tup2) () ); - ASSERT (11+12+13 == func::closure(unbound_functor3,tup3) () ); + ASSERT (-1 == closure(unbound_functor0,tup0) () ); + ASSERT (11 == closure(unbound_functor1,tup1) () ); + ASSERT (11+12 == closure(unbound_functor2,tup2) () ); + ASSERT (11+12+13 == closure(unbound_functor3,tup3) () ); // finally combine all techniques.... diff --git a/tests/lib/meta/function-composition-test.cpp b/tests/lib/meta/function-composition-test.cpp index a9e8d66ce..cfeb26539 100644 --- a/tests/lib/meta/function-composition-test.cpp +++ b/tests/lib/meta/function-composition-test.cpp @@ -28,35 +28,19 @@ #include "lib/meta/function-closure.hpp" #include "meta/typelist-diagnostics.hpp" -#include - -using ::test::Test; -using std::string; -using std::cout; -using std::endl; - namespace lumiera { namespace typelist{ -namespace test { +namespace test { + using ::test::Test; using func::applyFirst; using func::applyLast; + using func::PApply; namespace { // test functions - - - typedef Types< Num<1> ////////////////////////TODO kill kill kill - , Num<2> - , Num<3> - >::List List1; - typedef Types< Num<5> - , Num<6> - , Num<7> - >::List List2; - Num<1> _1_; Num<2> _2_; Num<3> _3_;