diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 934783b..35d22b0 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -16,50 +16,66 @@ #include #include #include +#include +#include +#include +#include #define BOOST_PP_ITERATION_LIMITS ( 0, 8 ) #define BOOST_PP_FILENAME_1 +namespace chaiscript +{ + namespace detail + { + template + struct bind_helper + { + template + static boost::function go(const F &f, const V &v) + { + return boost::function(); + } + }; + #include BOOST_PP_ITERATE() + template + struct pop_front + { + typedef typename boost::function_types::function_type< + typename boost::mpl::push_front< + typename boost::mpl::pop_front >::type, + typename boost::function_types::result_type::type + >::type + >::type type; + }; + + template + boost::function::type> bind_first(T t, const U &u) + { + return bind_helper::value, + typename pop_front::type>::go(t, u); + } + } +} # endif #else # define n BOOST_PP_ITERATION() # define m BOOST_PP_INC(n) -namespace chaiscript -{ - - template - boost::function - bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) + + template + struct bind_helper { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); - } + template + static boost::function go(const F &f, const V &v) + { + return boost::bind(f, v BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); + } + }; - template - boost::function - bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const O &o) - { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); - } - - template - boost::function - bind_first(Ret (*f)(BOOST_PP_ENUM_PARAMS(m, Param)), const O &o) - { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); - } - - template - boost::function - bind_first(const boost::function &f, const O &o) - { - return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _)); - } - - -} #endif diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 5bee2d0..4f3b641 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -378,7 +378,7 @@ namespace chaiscript virtual Boxed_Value operator()(const std::vector ¶ms) const { - return Do_Call::result_type>::go(m_f, params); + return detail::Do_Call::result_type>::go(m_f, params); } virtual int get_arity() const diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index c3c18f1..4853654 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -44,26 +44,30 @@ namespace chaiscript int expected; }; - template - struct Do_Call - { - template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) - { - return Handle_Return::handle(call_func(fun, params)); - } - }; + namespace detail + { - template<> - struct Do_Call - { - template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + template + struct Do_Call { - call_func(fun, params); - return Handle_Return::handle(); + template + static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + { + return Handle_Return::handle(call_func(fun, params)); + } }; - }; + + template<> + struct Do_Call + { + template + static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) + { + call_func(fun, params); + return Handle_Return::handle(); + }; + }; + } } #define BOOST_PP_ITERATION_LIMITS ( 0, 10 ) diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index bd9da43..8242a06 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -74,13 +74,13 @@ namespace chaiscript template Proxy_Function fun(T t, const Q &q) { - return detail::fun_helper(bind_first(t, q)); + return detail::fun_helper(detail::bind_first(t, q)); } template Proxy_Function fun(T t, const Q &q, const R &r) { - return detail::fun_helper(bind_first(bind_first(t, q), r)); + return detail::fun_helper(detail::bind_first(detail::bind_first(t, q), r)); } }