diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index fb1418e..25ff980 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -54,6 +54,23 @@ namespace chaiscript { namespace detail { + template + struct Indexes + { + }; + + template + struct Make_Indexes + { + typedef typename Make_Indexes::indexes indexes; + }; + + template + struct Make_Indexes<0, I...> + { + typedef Indexes indexes; + }; + /** * Used by Proxy_Function_Impl to return a list of all param types * it contains. @@ -66,77 +83,40 @@ namespace chaiscript } - // Forward declaration - template - struct Try_Cast; - - template - struct Try_Cast - { - static void do_try(const std::vector ¶ms, size_t generation, const Type_Conversions &t_conversions) - { - boxed_cast(params[generation], &t_conversions); - Try_Cast::do_try(params, generation+1, t_conversions); - } - }; - - // 0th case - template<> - struct Try_Cast<> - { - static void do_try(const std::vector &, size_t, const Type_Conversions &) - { - } - }; - - /** * Used by Proxy_Function_Impl to determine if it is equivalent to another * Proxy_Function_Impl object. This function is primarily used to prevent * registration of two functions with the exact same signatures */ - template - bool compare_types_cast(Ret (*)(Params...), + template + bool compare_types_cast(Indexes, Ret (*)(Params...), const std::vector ¶ms, const Type_Conversions &t_conversions) { try { - Try_Cast::do_try(params, 0, t_conversions); + std::initializer_list{(boxed_cast(params[I], &t_conversions), nullptr)...}; + return true; } catch (const exception::bad_boxed_cast &) { return false; } - return true; } - template - struct Call_Func - { - - template - static Ret do_call(const Callable &f, - const std::vector ¶ms, const Type_Conversions &t_conversions, InnerParams &&... innerparams) - { - return Call_Func::do_call(f, params, t_conversions, std::forward(innerparams)..., params[sizeof...(Params) - count]); - } - }; - template - struct Call_Func + bool compare_types_cast(Ret (*f)(Params...), + const std::vector ¶ms, const Type_Conversions &t_conversions) { -#ifdef CHAISCRIPT_MSVC -#pragma warning(push) -#pragma warning(disable : 4100) /// Disable unreferenced formal parameter warning, which only shows up in MSVC I don't think there's any way around it \todo evaluate this -#endif - template - static Ret do_call(const Callable &f, - const std::vector &, const Type_Conversions &t_conversions, InnerParams &&... innerparams) - { - return f(boxed_cast(std::forward(innerparams), &t_conversions)...); - } -#ifdef CHAISCRIPT_MSVC -#pragma warning(pop) -#endif - }; + typedef typename Make_Indexes::indexes indexes; + return compare_types_cast(indexes(), f, params, t_conversions); + } + + + template + Ret call_func(const chaiscript::dispatch::detail::Function_Signature &, Indexes, const Callable &f, + const std::vector ¶ms, const Type_Conversions &t_conversions) + { + return f(boxed_cast(params[I], &t_conversions)...); + } + /** * Used by Proxy_Function_Impl to perform typesafe execution of a function. @@ -145,15 +125,11 @@ namespace chaiscript * the bad_boxed_cast is passed up to the caller. */ template - Ret call_func(const chaiscript::dispatch::detail::Function_Signature &, const Callable &f, + Ret call_func(const chaiscript::dispatch::detail::Function_Signature &sig, const Callable &f, const std::vector ¶ms, const Type_Conversions &t_conversions) { - if (params.size() == sizeof...(Params)) - { - return Call_Func::do_call(f, params, t_conversions); - } - - throw exception::arity_error(static_cast(params.size()), sizeof...(Params)); + typedef typename Make_Indexes::indexes indexes; + return call_func(sig, indexes(), f, params, t_conversions); } } diff --git a/readme.md b/readme.md index cc3af26..32cb703 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,10 @@ Master Status: [![Linux Build Status](https://travis-ci.org/ChaiScript/ChaiScrip Develop Status: [![Linux Build Status](https://travis-ci.org/ChaiScript/ChaiScript.png?branch=develop)](https://travis-ci.org/ChaiScript/ChaiScript) [![Windows Build status](https://ci.appveyor.com/api/projects/status/6u3r4s81kkjqmsqw/branch/develop?svg=true)](https://ci.appveyor.com/project/lefticus/chaiscript/branch/develop) [![Coverage Status](https://coveralls.io/repos/ChaiScript/ChaiScript/badge.png?branch=develop)](https://coveralls.io/r/ChaiScript/ChaiScript?branch=develop) + + Coverity Scan Build Status + ChaiScript