diff --git a/src/lib/meta/function-closure.hpp b/src/lib/meta/function-closure.hpp index 85a9c7ef7..c86958ba7 100644 --- a/src/lib/meta/function-closure.hpp +++ b/src/lib/meta/function-closure.hpp @@ -65,19 +65,38 @@ namespace typelist{ struct Apply; + template<> //__________________________________ + struct Apply<0> ///< Apply function without Arguments + { + template + static RET + invoke (FUN& f, TUP&) + { + return f (); + } + + template + static RET + bind (FUN& f, TUP&) + { + return std::tr1::bind (f); + } + }; + + template<> //_________________________________ struct Apply<1> ///< Apply function with 1 Argument { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f (element<1>(arg)); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg)); } @@ -87,18 +106,18 @@ namespace typelist{ template<> //_________________________________ struct Apply<2> ///< Apply function with 2 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -110,9 +129,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<3> ///< Apply function with 3 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -120,9 +139,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -135,9 +154,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<4> ///< Apply function with 4 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -146,9 +165,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -162,9 +181,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<5> ///< Apply function with 5 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -174,9 +193,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -191,9 +210,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<6> ///< Apply function with 6 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -204,9 +223,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -222,9 +241,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<7> ///< Apply function with 7 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -236,9 +255,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -255,9 +274,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<8> ///< Apply function with 8 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -270,9 +289,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -290,9 +309,9 @@ namespace typelist{ template<> //_________________________________ struct Apply<9> ///< Apply function with 9 Arguments { - template + template static RET - invoke (FUN f, TUP & arg) + invoke (FUN& f, TUP & arg) { return f ( element<1>(arg) , element<2>(arg) @@ -306,9 +325,9 @@ namespace typelist{ ); } - template + template static RET - bind (FUN f, TUP & arg) + bind (FUN& f, TUP & arg) { return std::tr1::bind (f, element<1>(arg) , element<2>(arg) @@ -336,6 +355,8 @@ namespace typelist{ typedef typename FunctionSignature< function >::Args Args; typedef typename FunctionSignature< function >::Ret Ret; + typedef function BoundFunc; + enum { ARG_CNT = count::value }; @@ -347,11 +368,11 @@ namespace typelist{ : params_(args) { } - function bind (SIG& f) { return func::Apply::bind (f, params_); } - function bind (function const& f) { return func::Apply::bind (f, params_); } + BoundFunc bind (SIG& f) { return func::Apply::template bind (f, params_); } + BoundFunc bind (function& f) { return func::Apply::template bind (f, params_); } - Ret operator() (SIG& f) { return func::Apply::invoke (f, params_); } - Ret operator() (function const& f) { return func::Apply::invoke (f, params_); } + Ret operator() (SIG& f) { return func::Apply::template invoke (f, params_); } + Ret operator() (function& f) { return func::Apply::template invoke (f, params_); } };