diff --git a/boost/type_index/template_info.hpp b/boost/type_index/template_info.hpp index 3183cca..4d09194 100644 --- a/boost/type_index/template_info.hpp +++ b/boost/type_index/template_info.hpp @@ -6,20 +6,20 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BOOST_TYPE_INDEX_TEMPLATE_INFO_IMPL_HPP -#define BOOST_TYPE_INDEX_TEMPLATE_INFO_IMPL_HPP +#ifndef BOOST_TYPE_INDEX_TEMPLATE_INFO_HPP +#define BOOST_TYPE_INDEX_TEMPLATE_INFO_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif -/// \file template_info_impl.hpp + +/// \file template_info.hpp /// \brief Contains implementation of boost::template_info class. /// -/// boost::template_info class is used instead of boost::type_info in situations when RTTI is disabled. -/// -/// Consider including or instead of this file. +/// boost::template_info class is used instead of boost::type_index class in situations when RTTI is disabled. +/// It combines functionality of std::type_info and std::type_index. #include #include @@ -30,6 +30,15 @@ #include #include +#if !defined(BOOST_NO_IOSTREAM) +#if !defined(BOOST_NO_IOSFWD) +#include // for std::basic_ostream +#else +#include +#endif +#endif + + namespace boost { namespace detail { @@ -51,12 +60,12 @@ namespace detail { #elif defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) template -inline void lazy_function_signature_assert() BOOST_NOEXCEPT {} +inline void lazy_function_signature_assert(){} #elif defined(__FUNCSIG__) template -inline void lazy_function_signature_assert() BOOST_NOEXCEPT {} +inline void lazy_function_signature_assert(){} #define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __FUNCSIG__ #elif defined(__PRETTY_FUNCTION__) \ @@ -67,13 +76,13 @@ inline void lazy_function_signature_assert() BOOST_NOEXCEPT {} || defined(__DMC__) template -inline void lazy_function_signature_assert() BOOST_NOEXCEPT {} +inline void lazy_function_signature_assert(){} #define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __PRETTY_FUNCTION__ #else template -inline void lazy_function_signature_assert() BOOST_NOEXCEPT { +inline void lazy_function_signature_assert() { BOOST_STATIC_ASSERT_MSG( sizeof(T) && false, "TypeIndex library could not detect your compiler. " @@ -140,7 +149,7 @@ inline void lazy_function_signature_assert() BOOST_NOEXCEPT { /// Copyable type_info that does not require RTTI and could store const, /// volatile and references if constructed via construct_with_cvr() -class template_info: boost::noncopyable { +class template_info { private: const char* name_; @@ -151,10 +160,15 @@ private: /// @endcond public: - /// Factory method for constructing template_index instance for type T. + /// Default constructor. + template_info() BOOST_NOEXCEPT + : name_(detail::ctti::name()) + {} + + /// Factory method for constructing template_info instance for type T. /// Strips const, volatile and & modifiers from T template - static const template_info& construct() BOOST_NOEXCEPT { + static const template_info& construct(){ typedef BOOST_DEDUCED_TYPENAME boost::remove_reference::type no_ref_t; typedef BOOST_DEDUCED_TYPENAME boost::remove_cv::type no_cvr_t; @@ -164,21 +178,21 @@ public: , "Your EDG-based compiler seems to mistakenly distinguish 'int' from 'signed int', in typeid() expressions."); #endif - static const template_index ret(detail::ctti::name()) + static const template_info ret(detail::ctti::name()); return ret; } - /// Factory method for constructing template_index instance for type T. + /// Factory method for constructing template_info instance for type T. /// Does not strip const, volatile and & modifiers from T template - static const template_info& construct_with_cvr() BOOST_NOEXCEPT { + static const template_info& construct_with_cvr() { # if (defined(__EDG_VERSION__) && __EDG_VERSION__ < 245) \ || (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 744) BOOST_STATIC_ASSERT_MSG( !boost::is_arithmetic::type::value , "Your EDG-based compiler seems to mistakenly distinguish 'int' from 'signed int', in typeid() expressions."); #endif - static const template_index ret(detail::ctti::name()) + static const template_info ret(detail::ctti::name()); return ret; } @@ -199,6 +213,7 @@ public: return std::string(name_, std::strlen(name_ + detail::ctti_skip_size_at_end)); } + /// @cond bool operator == (const template_info& rhs) const BOOST_NOEXCEPT { return !std::strcmp(name_, rhs.name()); } @@ -206,36 +221,71 @@ public: bool operator != (const template_info& rhs) const BOOST_NOEXCEPT { return !!std::strcmp(name_, rhs.name()); } - + + bool operator < (const template_info& rhs) const BOOST_NOEXCEPT { + return std::strcmp(name_, rhs.name()) < 0; + } + + bool operator > (const template_info& rhs) const BOOST_NOEXCEPT { + return std::strcmp(name_, rhs.name()) > 0; + } + + bool operator <= (const template_info& rhs) const BOOST_NOEXCEPT { + return std::strcmp(name_, rhs.name()) <= 0; + } + + bool operator >= (const template_info& rhs) const BOOST_NOEXCEPT { + return std::strcmp(name_, rhs.name()) >= 0; + } + /// @endcond + /// Function for getting hash value std::size_t hash_code() const BOOST_NOEXCEPT { return boost::hash_range(name_, name_ + std::strlen(name_ + detail::ctti_skip_size_at_end)); } }; -/// Method for constructing template_index instance for type T. +/// Method for constructing template_info instance for type T. /// Strips const, volatile and & modifiers from T. template inline const template_info& template_id() BOOST_NOEXCEPT { - return template_index::construct(); + return template_info::construct(); } -/// Factory method for constructing template_index instance for type T. +/// Factory method for constructing template_info instance for type T. /// Does not strip const, volatile and & modifiers from T. /// If T has no const, volatile, & and && modifiers, then returns exactly /// the same result as in case of calling `template_id()`. template inline const template_info& template_id_with_cvr() BOOST_NOEXCEPT { - return template_index::construct_with_cvr(); + return template_info::construct_with_cvr(); } /* *************** template_info free functions ******************* */ -/// hash_value function overload for template_index + +#ifndef BOOST_NO_IOSTREAM +#ifdef BOOST_NO_TEMPLATED_IOSTREAMS +/// Ostream operator that will output demangled name +inline std::ostream& operator<<(std::ostream& ostr, template_info const& ind) { + ostr << ind.name_demangled(); + return ostr; +} +#else +/// Ostream operator that will output demangled name +template +inline std::basic_ostream& operator<<(std::basic_ostream& ostr, template_info const& ind) { + ostr << ind.name_demangled(); + return ostr; +} +#endif // BOOST_NO_TEMPLATED_IOSTREAMS +#endif // BOOST_NO_IOSTREAM + +/// hash_value function overload for template_info inline std::size_t hash_value(template_info const& v) BOOST_NOEXCEPT { return v.hash_code(); } } // namespace boost -#endif // BOOST_TYPE_INDEX_TEMPLATE_INDEX_IMPL_HPP +#endif // BOOST_TYPE_INDEX_TEMPLATE_INFO_HPP diff --git a/boost/type_index/type_info.hpp b/boost/type_index/type_info.hpp index dc04697..04a0c70 100644 --- a/boost/type_index/type_info.hpp +++ b/boost/type_index/type_info.hpp @@ -262,16 +262,16 @@ inline std::size_t hash_value(type_index const& v) BOOST_NOEXCEPT { namespace boost { -typedef template_index type_index; +typedef template_info type_index; template inline const type_index& type_id() BOOST_NOEXCEPT { - return template_index::construct(); + return template_info::construct(); } template inline const type_index& type_id_with_cvr() BOOST_NOEXCEPT { - return template_index::construct_with_cvr(); + return template_info::construct_with_cvr(); } template