From 3a775097dd402840c83cbf893baf0d040db78b01 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 17 Aug 2014 06:52:11 -0600 Subject: [PATCH] Reduce size of Any template wrapper. --- include/chaiscript/dispatchkit/any.hpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 6704bb3..c074898 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -44,17 +44,27 @@ namespace chaiscript { private: struct Data { + Data(const std::type_info &t_type) + : m_type(t_type) + { + } + virtual ~Data() {} virtual void *data() = 0; - virtual const std::type_info &type() const = 0; + const std::type_info &type() const + { + return m_type; + } + virtual std::unique_ptr clone() const = 0; + const std::type_info &m_type; }; template struct Data_Impl : Data { Data_Impl(T t_type) - : m_type(typeid(T)), + : Data(typeid(T)), m_data(std::move(t_type)) { } @@ -66,19 +76,13 @@ namespace chaiscript { return &m_data; } - const std::type_info &type() const CHAISCRIPT_OVERRIDE - { - return m_type; - } - std::unique_ptr clone() const CHAISCRIPT_OVERRIDE { return std::unique_ptr(new Data_Impl(m_data)); } Data_Impl &operator=(const Data_Impl&) = delete; - - const std::type_info &m_type; + T m_data; }; @@ -127,7 +131,6 @@ namespace chaiscript { } else { throw chaiscript::detail::exception::bad_any_cast(); } - }