From 3feb08443808b267baa8a9b7d423eeac83bdd231 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 22 Aug 2017 22:22:47 -0600 Subject: [PATCH] constexpr user_type objects --- .../dispatchkit/proxy_functions.hpp | 28 +++++++++++-------- .../dispatchkit/type_conversions.hpp | 4 ++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 75a67a64..b1a096e6 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -52,14 +52,12 @@ namespace chaiscript { public: Param_Types() - : m_has_types(false), - m_doti(user_type()) + : m_has_types(false) {} explicit Param_Types(std::vector> t_types) : m_types(std::move(t_types)), - m_has_types(false), - m_doti(user_type()) + m_has_types(false) { update_has_types(); } @@ -77,13 +75,14 @@ namespace chaiscript std::vector convert(std::vector vals, const Type_Conversions_State &t_conversions) const { + constexpr auto dynamic_object_type_info = user_type(); for (size_t i = 0; i < vals.size(); ++i) { const auto &name = m_types[i].first; if (!name.empty()) { const auto &bv = vals[i]; - if (!bv.get_type_info().bare_equal(m_doti)) + if (!bv.get_type_info().bare_equal(dynamic_object_type_info)) { const auto &ti = m_types[i].second; if (!ti.is_undef()) @@ -116,6 +115,7 @@ namespace chaiscript // second result: needs conversions std::pair match(const std::vector &vals, const Type_Conversions_State &t_conversions) const noexcept { + constexpr auto dynamic_object_type_info = user_type(); bool needs_conversion = false; if (!m_has_types) { return std::make_pair(true, needs_conversion); } @@ -127,7 +127,7 @@ namespace chaiscript if (!name.empty()) { const auto &bv = vals[i]; - if (bv.get_type_info().bare_equal(m_doti)) + if (bv.get_type_info().bare_equal(dynamic_object_type_info)) { try { const Dynamic_Object &d = boxed_cast(bv, &t_conversions); @@ -180,7 +180,6 @@ namespace chaiscript std::vector> m_types; bool m_has_types; - Type_Info m_doti; }; @@ -251,12 +250,16 @@ namespace chaiscript static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions_State &t_conversions) noexcept { + constexpr auto boxed_value_ti = user_type(); + constexpr auto boxed_number_ti = user_type(); + constexpr auto function_ti = user_type>(); + if (ti.is_undef() - || ti.bare_equal(user_type()) + || ti.bare_equal(boxed_value_ti) || (!bv.get_type_info().is_undef() - && ( (ti.bare_equal(user_type()) && bv.get_type_info().is_arithmetic()) + && ( (ti.bare_equal(boxed_number_ti) && bv.get_type_info().is_arithmetic()) || ti.bare_equal(bv.get_type_info()) - || bv.get_type_info().bare_equal(user_type >()) + || bv.get_type_info().bare_equal(function_ti) || t_conversions->converts(ti, bv.get_type_info()) ) ) @@ -754,8 +757,8 @@ namespace chaiscript { return false; } - - return vals[0].get_type_info().bare_equal(user_type()); + constexpr auto class_type_info = user_type(); + return vals[0].get_type_info().bare_equal(class_type_info); } protected: @@ -804,6 +807,7 @@ namespace chaiscript return {user_type(), user_type()}; } + std::vector m_param_types{user_type(), user_type()}; T Class::* m_attr; }; } diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index dd327bf7..85991b4b 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -123,6 +123,7 @@ namespace chaiscript public: static Boxed_Value cast(const Boxed_Value &t_from) { + if (t_from.get_type_info().bare_equal(chaiscript::user_type())) { if (t_from.is_pointer()) @@ -373,7 +374,8 @@ namespace chaiscript template bool convertable_type() const noexcept { - return thread_cache().count(user_type().bare_type_info()) != 0; + constexpr auto type = user_type().bare_type_info(); + return thread_cache().count(type) != 0; } template