From 0b812942d422046660409d021aef61a998edcf5b Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 22 May 2015 11:35:58 -0600 Subject: [PATCH] Finish removing std::function<> --- .../dispatchkit/callable_traits.hpp | 25 +++++++++++++++++++ .../dispatchkit/register_function.hpp | 17 ++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/include/chaiscript/dispatchkit/callable_traits.hpp b/include/chaiscript/dispatchkit/callable_traits.hpp index 8a95d7e..49978d2 100644 --- a/include/chaiscript/dispatchkit/callable_traits.hpp +++ b/include/chaiscript/dispatchkit/callable_traits.hpp @@ -10,6 +10,31 @@ namespace chaiscript { namespace dispatch { namespace detail { + template + struct Const_Caller + { + Const_Caller(Ret (Class::*t_func)(Param...) const) : m_func(t_func) {} + + template + Ret operator()(const Class &o, Inner&& ... inner) const { + return (o.*m_func)(std::forward(inner)...); + } + + Ret (Class::*m_func)(Param...) const; + }; + + template + struct Caller + { + Caller(Ret (Class::*t_func)(Param...)) : m_func(t_func) {} + + template + Ret operator()(Class &o, Inner&& ... inner) const { + return (o.*m_func)(std::forward(inner)...); + } + + Ret (Class::*m_func)(Param...); + }; template struct Function_Signature diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 093bd41..438c723 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -126,17 +126,26 @@ namespace chaiscript } template - Proxy_Function fun(Ret (Class::*func)(Param...) const) + Proxy_Function fun(Ret (Class::*t_func)(Param...) const) { + auto call = dispatch::detail::Const_Caller(t_func); + return Proxy_Function( - chaiscript::make_shared::Signature>>(dispatch::detail::to_function(func))); + chaiscript::make_shared>(call)); } template - Proxy_Function fun(Ret (Class::*func)(Param...)) + Proxy_Function fun(Ret (Class::*t_func)(Param...)) { + auto call = dispatch::detail::Caller(t_func); + return Proxy_Function( - chaiscript::make_shared::Signature>>(dispatch::detail::to_function(func))); + chaiscript::make_shared>(call)); + +/* + return Proxy_Function( + chaiscript::make_shared::Signature>>(dispatch::detail::to_function(t_func))); +*/ }