From b8265cdb4fcdadf116419f4ad6773e162101bbb4 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Fri, 21 Feb 2014 17:49:32 +0400 Subject: [PATCH] Minor changes to docs --- doc/type_index.qbk | 35 ++++++++++---------- include/boost/type_index.hpp | 8 ++++- include/boost/type_index/ctti_type_index.hpp | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/doc/type_index.qbk b/doc/type_index.qbk index a1223f6..d029d68 100644 --- a/doc/type_index.qbk +++ b/doc/type_index.qbk @@ -59,13 +59,6 @@ To start using Boost.TypeIndex: bti::type_index ``]] -[[`` - const std::type_info& -``][`` - const bti::type_info& // when reference to `std::type_info` is required - bti::type_index // other cases -``]] - [[`` typeid(T) typeid(please_save_modifiers) @@ -77,6 +70,14 @@ To start using Boost.TypeIndex: bti::type_id().pretty_name() // human readable bti::type_id_runtime(variable) ``]] + +[[`` + const std::type_info& v1 = typeid(int); // when reference to `std::type_info` is required + const std::type_info* v2 = &typeid(int); // other cases +``][`` + const bti::type_info& v1 = bti::type_id().type_info(); + bti::type_index v2 = bti::type_id(); +``]] ] If you are using `type_id_runtime()` methods and RTTI is disabled, make sure that classes that are @@ -100,7 +101,7 @@ Here is how TypeIndex could be used in `boost/any.hpp`: virtual const bti::type_info & type() const BOOST_NOEXCEPT { // now works even with RTTI disabled - return bti::type_id()->type_info(); + return bti::type_id().type_info(); } ``]] ] @@ -147,7 +148,7 @@ public: // visitor interfaces template const bti::type_info& operator()(const T&) const BOOST_NOEXCEPT { - return bti::type_id()->type_info(); + return bti::type_id().type_info(); } }; @@ -234,8 +235,8 @@ Sometimes there may be a need to create your own type info system. This may be u [section Space and Performance] -* `ctti_type_info` uses macro for getting full text representation of function name which could lead to code bloat, -so prefer using `stl_type_info` type when possible. +* `ctti_type_index` uses macro for getting full text representation of function name which could lead to code bloat, +so prefer using `stl_type_index` type when possible. * `type_index` class hold a single pointer, so it is easy and fast to copy. * Calls to `const char* raw_name()` do not require dynamic memory allocation and usually just return a pointer to an array of chars in a read-only section of the binary image. * Comparison operators are optimized as much as possible, and will at worst execute a single `std::strcmp`. @@ -245,8 +246,8 @@ so prefer using `stl_type_info` type when possible. [section Code bloat] -Without RTTI TypeIndex library will switch from using `boost::typeind::stl_type_info` class to -`boost::typeind::ctti_type_info`. `boost::typeind::ctti_type_info` uses macro for getting full +Without RTTI TypeIndex library will switch from using `boost::typeind::stl_type_index` class to +`boost::typeind::ctti_type_index`. `boost::typeind::ctti_type_index` uses macro for getting full text representation of function name for each type that is passed to `type_id()` and `type_id_with_cvr()` functions. @@ -285,7 +286,7 @@ feature request to add your compiler to supported compilers list. Include Consider the following example: With `BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` and `BOOST_TYPE_INDEX_CTTI_END_SKIP` set to `0`, -`boost::typeind::ctti_type_info::construct().raw_name()` returns +`boost::typeind::ctti_type_index::type_id().raw_name()` returns "const char *__cdecl boost::detail::ctti::n(void)". Then you shall set `BOOST_TYPE_INDEX_CTTI_BEGIN_SKIP` to `sizeof("const char *__cdecl boost::detail::ctti<") - 1` and `BOOST_TYPE_INDEX_CTTI_END_SKIP` to `sizeof(">::n(void)") - 1`. @@ -297,8 +298,8 @@ and `BOOST_TYPE_INDEX_CTTI_END_SKIP` to `sizeof(">::n(void)") - 1`. Linking a binary from source files that were compiled with different RTTI flags is not a very good idea and may lead to a lot of surprises. However if there is a very strong need, TypeIndex library provides a solution for mixing sources: just define `BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY` -macro. This would lead to usage of `boost::typeind::ctti_type_info` instead of -`boost::typeind::stl_type_info` class. +macro. This would lead to usage of same type_index class (`boost::typeind::ctti_type_index` or +`boost::typeind::stl_type_index`) all around the project. [note Do not forget to rebuild *all* the projects with `BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY` macro defined ] @@ -310,7 +311,7 @@ RTTI flags: [table:diffs [[RTTI on] [RTTI off]] -[[`boost::typeind::stl_type_info get_integer();`] [`boost::typeind::ctti_type_info get_integer();`]] +[[`boost::typeind::stl_type_index get_integer();`] [`boost::typeind::ctti_type_index get_integer();`]] ] Such differences are usually not detected by linker and lead to errors at runtime. diff --git a/include/boost/type_index.hpp b/include/boost/type_index.hpp index 3592bcb..4025018 100644 --- a/include/boost/type_index.hpp +++ b/include/boost/type_index.hpp @@ -76,7 +76,7 @@ typedef type_index::type_info_t type_info; /// \def BOOST_TYPE_INDEX_REGISTER_CLASS -/// BOOST_TYPE_INDEX_REGISTER_CLASS is a helper macro that is used to help to emulate RTTI. +/// \def BOOST_TYPE_INDEX_REGISTER_CLASSis used to help to emulate RTTI. /// Put this macro into the public section of polymorphic class to allow runtime type detection. /// /// Depending on the typeid() availability this macro will expand to nothing or to virtual helper function @@ -106,6 +106,12 @@ typedef type_index::type_info_t type_info; /// \endcode #define BOOST_TYPE_INDEX_REGISTER_CLASS nothing-or-some-virtual-functions +/// \def BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY +/// BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY is a helper macro that must be defined if mixing +/// RTTI on/off modules. See "Mixing sources with RTTI on and RTTI off" section of documentation +/// for more info. +#define BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY + #endif // defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) diff --git a/include/boost/type_index/ctti_type_index.hpp b/include/boost/type_index/ctti_type_index.hpp index 752057a..36eb595 100644 --- a/include/boost/type_index/ctti_type_index.hpp +++ b/include/boost/type_index/ctti_type_index.hpp @@ -57,7 +57,7 @@ inline const detail::ctti_data& ctti_construct() BOOST_NOEXCEPT { } /// \class ctti_type_index -/// This class is a wrapper that pretends to work exactly like stl_type_info, but does +/// This class is a wrapper that pretends to work exactly like stl_type_index, but does /// not require RTTI support. For description of functions see type_index_facade. /// /// This class produces slightly longer type names, so consider using stl_type_index