From a112d97141deca9c5bf4089c9283b2f6978a5d67 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 23 Jun 2015 11:48:01 -0600 Subject: [PATCH] Simplify a couple of random things --- include/chaiscript/dispatchkit/boxed_cast_helper.hpp | 9 ++++----- include/chaiscript/dispatchkit/type_info.hpp | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 3c96931..8f478bf 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -58,6 +58,7 @@ namespace chaiscript { }; + /// Cast_Helper_Inner for casting to a const * type template struct Cast_Helper_Inner @@ -81,11 +82,11 @@ namespace chaiscript typedef Result * Result_Type; static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { - if (ob.is_ref()) + if (!ob.get_type_info().is_const() && ob.get_type_info() == typeid(Result)) { - return &(ob.get().cast >()).get(); + return static_cast(throw_if_null(ob.get_ptr())); } else { - return (ob.get().cast >()).get(); + throw chaiscript::detail::exception::bad_any_cast(); } } }; @@ -149,7 +150,6 @@ namespace chaiscript { }; - /// Cast_Helper_Inner for casting to a const std::shared_ptr & type template struct Cast_Helper_Inner > : Cast_Helper_Inner > @@ -162,7 +162,6 @@ namespace chaiscript }; - /// Cast_Helper_Inner for casting to a Boxed_Value type template<> struct Cast_Helper_Inner diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index 81ec083..e15e508 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -62,7 +62,7 @@ namespace chaiscript CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { - return ti.m_type_info == m_type_info + return ti.m_type_info == m_type_info || (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info); } @@ -87,7 +87,7 @@ namespace chaiscript CHAISCRIPT_CONSTEXPR bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } CHAISCRIPT_CONSTEXPR bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } CHAISCRIPT_CONSTEXPR bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } - CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef || m_bare_type_info == nullptr; } + CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef; } CHAISCRIPT_CONSTEXPR bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } std::string name() const @@ -100,7 +100,7 @@ namespace chaiscript } } - std::string bare_name() const + std::string bare_name() const { if (m_bare_type_info) {