From e0234d942e8ed00a600ee8e48e08b0f86444570f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 22 May 2015 19:40:56 -0600 Subject: [PATCH] Various cleanups and fixes for older compilers --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 14 ++++---- .../chaiscript/dispatchkit/boxed_number.hpp | 22 ++++++------- .../dispatchkit/callable_traits.hpp | 33 ++++++++++--------- .../dispatchkit/proxy_functions.hpp | 12 +++---- .../dispatchkit/proxy_functions_detail.hpp | 2 +- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index ad31f6b..650124c 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -243,18 +243,18 @@ namespace chaiscript template ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { - // cppcheck-suppress syntaxError - typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); - //In the interest of runtime safety for the m, we prefer the at() method for [] access, //to throw an exception in an out of bounds condition. m->add( - fun(std::function - (std::mem_fn(static_cast(&ContainerType::at)))), "[]"); + fun( + [](ContainerType &c, int index) -> typename ContainerType::reference { + return c.at(index); + }), "[]"); + m->add( fun( - [](const ContainerType *c, int index) -> typename ContainerType::const_reference { - return c->at(index); + [](const ContainerType &c, int index) -> typename ContainerType::const_reference { + return c.at(index); }), "[]"); return m; diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index a57ed7a..fa3ba6c 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -60,7 +60,7 @@ namespace chaiscript { private: template - static void check_divide_by_zero(T t, typename std::enable_if::value>::type* = nullptr) + inline static void check_divide_by_zero(T t, typename std::enable_if::value>::type* = nullptr) { #ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO if (t == 0) { @@ -70,7 +70,7 @@ namespace chaiscript } template - static void check_divide_by_zero(T, typename std::enable_if::value>::type* = nullptr) + inline static void check_divide_by_zero(T, typename std::enable_if::value>::type* = nullptr) { } @@ -78,7 +78,7 @@ namespace chaiscript { template - static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) + inline static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) { switch (t_oper) { @@ -103,7 +103,7 @@ namespace chaiscript struct binary { template - static Boxed_Value go(Operators::Opers t_oper, T &t, const U &u, const Boxed_Value &t_lhs) + inline static Boxed_Value go(Operators::Opers t_oper, T &t, const U &u, const Boxed_Value &t_lhs) { switch (t_oper) { @@ -140,7 +140,7 @@ namespace chaiscript struct binary_int { template - static Boxed_Value go(Operators::Opers t_oper, T &t, const U &u, const Boxed_Value &t_lhs) + inline static Boxed_Value go(Operators::Opers t_oper, T &t, const U &u, const Boxed_Value &t_lhs) { switch (t_oper) { @@ -173,7 +173,7 @@ namespace chaiscript struct const_binary_int { template - static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) + inline static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) { switch (t_oper) { @@ -201,7 +201,7 @@ namespace chaiscript struct const_binary { template - static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) + inline static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) { switch (t_oper) { @@ -227,7 +227,7 @@ namespace chaiscript template struct Go { - static Boxed_Value go(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) + inline static Boxed_Value go(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { @@ -249,7 +249,7 @@ namespace chaiscript template struct Go { - static Boxed_Value go(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) + inline static Boxed_Value go(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { if (t_oper > Operators::boolean_flag && t_oper < Operators::non_const_flag) { @@ -269,7 +269,7 @@ namespace chaiscript }; template - static Boxed_Value oper_rhs(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) + inline static Boxed_Value oper_rhs(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { const auto &inp_ = t_rhs.get_type_info(); @@ -310,7 +310,7 @@ namespace chaiscript } } - static Boxed_Value oper(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) + inline static Boxed_Value oper(Operators::Opers t_oper, const Boxed_Value &t_lhs, const Boxed_Value &t_rhs) { const Type_Info &inp_ = t_lhs.get_type_info(); diff --git a/include/chaiscript/dispatchkit/callable_traits.hpp b/include/chaiscript/dispatchkit/callable_traits.hpp index e1fe612..5ffa093 100644 --- a/include/chaiscript/dispatchkit/callable_traits.hpp +++ b/include/chaiscript/dispatchkit/callable_traits.hpp @@ -47,29 +47,32 @@ namespace chaiscript { Ret (Class::*m_func)(Param...); }; + template struct Function_Signature { - - template - static Ret deduce_ret_type(Function_Signature *); - - typedef T Signature; - typedef Function_Signature *ptr_type; - typedef decltype(deduce_ret_type(ptr_type(nullptr))) Return_Type; - }; + template + struct Function_Signature + { + typedef Ret Return_Type; + typedef Ret (Signature)(Params...); + }; + + template + struct Function_Signature + { + typedef Ret Return_Type; + typedef Ret (Signature)(Params...); + }; + + template struct Callable_Traits { - - template - static Function_Signature deduce_sig_type(Ret (T::*)(Param...) const); - - typedef typename decltype(deduce_sig_type(&T::operator()))::Signature Signature; - typedef decltype(deduce_sig_type(&T::operator())) Signature_Object; - typedef typename Signature_Object::Return_Type Return_Type; + typedef typename Function_Signature::Signature Signature; + typedef typename Function_Signature::Return_Type Return_Type; }; } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 35dc100..e0a413a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -558,7 +558,7 @@ namespace chaiscript public: Proxy_Function_Callable_Impl(Callable f) : Proxy_Function_Impl_Base(detail::build_param_type_list(static_cast(nullptr))), - m_f(std::move(f)), m_dummy_func(nullptr) + m_f(std::move(f)) { } @@ -566,7 +566,7 @@ namespace chaiscript virtual bool compare_types_with_cast(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { - return detail::compare_types_cast(m_dummy_func, vals, t_conversions); + return detail::compare_types_cast(static_cast(nullptr), vals, t_conversions); } virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE @@ -582,10 +582,8 @@ namespace chaiscript return detail::Do_Call::template go(m_f, params, t_conversions); } - private: Callable m_f; - Func *m_dummy_func; }; @@ -611,17 +609,16 @@ namespace chaiscript public: Assignable_Proxy_Function_Impl(std::reference_wrapper> t_f, std::shared_ptr> t_ptr) : Assignable_Proxy_Function(detail::build_param_type_list(static_cast(nullptr))), - m_f(std::move(t_f)), m_shared_ptr_holder(std::move(t_ptr)), m_dummy_func(nullptr) + m_f(std::move(t_f)), m_shared_ptr_holder(std::move(t_ptr)) { assert(!m_shared_ptr_holder || m_shared_ptr_holder.get() == &m_f.get()); - } virtual ~Assignable_Proxy_Function_Impl() {} virtual bool compare_types_with_cast(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { - return detail::compare_types_cast(m_dummy_func, vals, t_conversions); + return detail::compare_types_cast(static_cast(nullptr), vals, t_conversions); } virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE @@ -648,7 +645,6 @@ namespace chaiscript private: std::reference_wrapper> m_f; std::shared_ptr> m_shared_ptr_holder; - Func *m_dummy_func; }; /// Attribute getter Proxy_Function implementation template diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index fbd1843..fb1418e 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -98,7 +98,7 @@ namespace chaiscript template bool compare_types_cast(Ret (*)(Params...), const std::vector ¶ms, const Type_Conversions &t_conversions) - { + { try { Try_Cast::do_try(params, 0, t_conversions); } catch (const exception::bad_boxed_cast &) {