From dc4fec2badbdca191685275d9d7d1adcdfbb3774 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Wed, 23 Oct 2013 19:15:26 +0400 Subject: [PATCH] Improved the documentation and static assertion added for situations when compiler is not detected and boost::template_index is used. --- boost/type_index.hpp | 7 +-- boost/type_index/template_index_impl.hpp | 60 +++++++++++++++++++----- boost/type_index/type_index_impl.hpp | 9 ++-- boost/type_index/type_index_minimal.hpp | 14 ++++-- libs/type_index/doc/type_index.qbk | 3 +- 5 files changed, 69 insertions(+), 24 deletions(-) diff --git a/boost/type_index.hpp b/boost/type_index.hpp index eab0960..b333b0d 100644 --- a/boost/type_index.hpp +++ b/boost/type_index.hpp @@ -11,9 +11,10 @@ /// \file type_index.hpp /// \brief Includes all the headers of the Boost.TypeIndex library. /// -/// By inclusion of this file both classes (`type_index` (if RTTI is on) and `template_index`) will be available. -/// Consider including `` if you do not whant to include `template_index` class -/// while RTTI is available (this is recommended). +/// By inclusion of this file both classes (boost::type_index if RTTI is on and boost::template_index) will be available. +/// +/// Consider including if you do not whant to include +/// boost::template_index class while RTTI is available (this is recommended). // MS compatible compilers support #pragma once #if defined(_MSC_VER) diff --git a/boost/type_index/template_index_impl.hpp b/boost/type_index/template_index_impl.hpp index df419f8..a64cea4 100644 --- a/boost/type_index/template_index_impl.hpp +++ b/boost/type_index/template_index_impl.hpp @@ -20,12 +20,11 @@ #endif /// \file template_index_impl.hpp -/// \brief Contains implementation of template_index class. +/// \brief Contains implementation of boost::template_index class. /// -/// Here is defined the `boost::template_index` class, that is used instead of `boost::type_index` -/// class in situations when RTTI is disabled. +/// boost::template_index class is used instead of boost::type_index class in situations when RTTI is disabled. /// -/// Consider including `` or `` instead of this file. +/// Consider including or instead of this file. #include #include @@ -48,21 +47,57 @@ namespace boost { namespace detail { +#if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) + +/// \def BOOST_TYPE_INDEX_FUNCTION_SIGNATURE +/// BOOST_TYPE_INDEX_FUNCTION_SIGNATURE is used by boost::template_index class to +/// deduce the name of a template parameter. If your compiler is not recognized +/// by the TypeIndex library and you wish to work with boost::template_index, you may +/// define this macro by yourself. +/// +/// BOOST_TYPE_INDEX_FUNCTION_SIGNATURE must be defined to a compiler specific macro, +/// that outputs the WHOLE function signature, including template parameters. +/// +/// If your compiler is not recognised and BOOST_TYPE_INDEX_FUNCTION_SIGNATURE is not defined, +/// then a compile-time error will arise at any attempt to use boost::template_index class. +#define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE BOOST_CURRENT_FUNCTION + +#elif defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) + +template +inline void lazy_function_signature_assert(){} -#if defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) - // Do nothing #elif defined(__FUNCSIG__) -# define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __FUNCSIG__ -#elif defined(__GNUC__) \ + +template +inline void lazy_function_signature_assert(){} +#define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __FUNCSIG__ + +#elif defined(__PRETTY_FUNCTION__) \ + || defined(__GNUC__) \ || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \ || (defined(__ICC) && (__ICC >= 600)) \ || defined(__ghs__) \ || defined(__DMC__) -# define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __PRETTY_FUNCTION__ + +template +inline void lazy_function_signature_assert(){} +#define BOOST_TYPE_INDEX_FUNCTION_SIGNATURE __PRETTY_FUNCTION__ + #else -# error TypeIndex library could not detect your compiler. -# error Please make the BOOST_TYPE_INDEX_FUNCTION_SIGNATURE macro use -# error correct compiler macro for getting the whole function name. + +template +inline void lazy_function_signature_assert() { + BOOST_STATIC_ASSERT_MSG( + sizeof(T) && false, + "TypeIndex library could not detect your compiler. " + "Please make the BOOST_TYPE_INDEX_FUNCTION_SIGNATURE macro use " + "correct compiler macro for getting the whole function name. " + "Do not forget to also define BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP and " + "BOOST_TYPE_INDEX_CTTI_END_SKIP." + ); +} + #endif #if defined(BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP) && defined(BOOST_TYPE_INDEX_CTTI_END_SKIP) @@ -106,6 +141,7 @@ namespace detail { /// Returns raw name. Must be as short, as possible, to avoid code bloat static const char* n() BOOST_NOEXCEPT { + lazy_function_signature_assert(); return BOOST_TYPE_INDEX_FUNCTION_SIGNATURE + detail::ctti_skip_size_at_begin; } diff --git a/boost/type_index/type_index_impl.hpp b/boost/type_index/type_index_impl.hpp index ac96772..24aab0d 100644 --- a/boost/type_index/type_index_impl.hpp +++ b/boost/type_index/type_index_impl.hpp @@ -19,10 +19,13 @@ #endif /// \file type_index_impl.hpp -/// \brief Contains implementation of type_index class. +/// \brief Contains implementation of boost::type_index class. /// -/// Here is defined the type_index class, that is used in situations when RTTI is enabled. -/// Consider including `` or `` instead of this file. +/// boost::type_index class is used in situations when RTTI is enabled. +/// When RTTI is disabled or BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY macro is defined boost::template_index +/// is used instead. +/// +/// Consider including or instead of this file. #include diff --git a/boost/type_index/type_index_minimal.hpp b/boost/type_index/type_index_minimal.hpp index a7283ce..255d4cf 100644 --- a/boost/type_index/type_index_minimal.hpp +++ b/boost/type_index/type_index_minimal.hpp @@ -15,13 +15,10 @@ #endif /// \file type_index_minimal.hpp -/// \brief This is the header that required for ussage of type_index with/without RTTI. +/// \brief This is the header that required for ussage of boost::type_index with/without RTTI. /// -/// It includes only the minamally required headers and does the `typedef template_index type_index;` +/// It includes only the minamally required headers and does the 'typedef template_index type_index;' /// when RTTI is disabled. -/// -/// Define the BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY macro if you are mixing objects -/// compiled with different RTTI flags. #include @@ -61,6 +58,13 @@ inline type_index type_id_rtti_only(T* rtti_val) { #endif // BOOST_NO_RTTI +#if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) +/// \def BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY +/// Define the BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY macro if you are mixing objects +/// compiled with different RTTI flags. This will force the usage of boost::template_index +/// class instead of boost::type_index. +#define BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY +#endif // BOOST_TYPE_INDEX_DOXYGEN_INVOKED #endif // BOOST_TYPE_INDEX_TYPE_INDEX_MINIMAL_HPP diff --git a/libs/type_index/doc/type_index.qbk b/libs/type_index/doc/type_index.qbk index 91f8b1d..ba21465 100644 --- a/libs/type_index/doc/type_index.qbk +++ b/libs/type_index/doc/type_index.qbk @@ -106,8 +106,9 @@ i [section Compiler support] -TypeIndex has been tested and sucessfully work on MSVC2010, GCC-4.5, Clang-2.9. If your compiler is not in a list of tested compilers, you shall correctly define `BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` and `BOOST_TYPE_INDEX_CTTI_END_SKIP` macroses: +TypeIndex has been tested and sucessfully work on MSVC2010, GCC-4.5, Clang-2.9. If your compiler is not in a list of tested compilers, you shall correctly define `BOOST_TYPE_INDEX_FUNCTION_SIGNATURE`,`BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` and `BOOST_TYPE_INDEX_CTTI_END_SKIP` macroses: +# define `BOOST_TYPE_INDEX_FUNCTION_SIGNATURE` to a a compiler specific macro, that outputs the *whole* function signature, including template parameters # define `BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` and `BOOST_TYPE_INDEX_CTTI_END_SKIP` to `0` # get the output of `boost::detail::ctti::n()` # set `BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` equal to characters count before last occurrence of `int` in output