From 3a37ceedb7bb2571febd3320388751165c5a3f5b Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 8 Nov 2009 16:28:35 +0000 Subject: [PATCH] Rollback to r437 for bind_first implementation. The "cleaned up" version was a no-go in some cases --- include/chaiscript/dispatchkit/bind_first.hpp | 78 ++++++++----------- .../dispatchkit/proxy_functions.hpp | 2 +- .../dispatchkit/proxy_functions_detail.hpp | 36 ++++----- .../dispatchkit/register_function.hpp | 4 +- 4 files changed, 50 insertions(+), 70 deletions(-) diff --git a/include/chaiscript/dispatchkit/bind_first.hpp b/include/chaiscript/dispatchkit/bind_first.hpp index 35d22b0..934783b 100644 --- a/include/chaiscript/dispatchkit/bind_first.hpp +++ b/include/chaiscript/dispatchkit/bind_first.hpp @@ -16,66 +16,50 @@ #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) - - template - struct bind_helper +namespace chaiscript +{ + + template + boost::function + bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o) { - 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, _)); - } - }; + return boost::bind(f, o 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 ebd85b9..227ec45 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 detail::Do_Call::result_type>::go(m_f, params); + return 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 4853654..c3c18f1 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -44,30 +44,26 @@ namespace chaiscript int expected; }; - namespace detail - { - - template - struct Do_Call + template + struct Do_Call + { + template + static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) { - template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) - { - return Handle_Return::handle(call_func(fun, params)); - } - }; + return Handle_Return::handle(call_func(fun, params)); + } + }; - template<> - struct Do_Call + template<> + struct Do_Call + { + template + static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) { - template - static Boxed_Value go(const boost::function &fun, const std::vector ¶ms) - { - call_func(fun, params); - return Handle_Return::handle(); - }; + 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 8242a06..bd9da43 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(detail::bind_first(t, q)); + return detail::fun_helper(bind_first(t, q)); } template Proxy_Function fun(T t, const Q &q, const R &r) { - return detail::fun_helper(detail::bind_first(detail::bind_first(t, q), r)); + return detail::fun_helper(bind_first(bind_first(t, q), r)); } }