diff --git a/doc/type_index.qbk b/doc/type_index.qbk index 50c96a3..6800b7e 100644 --- a/doc/type_index.qbk +++ b/doc/type_index.qbk @@ -11,10 +11,10 @@ ] [section Motivation] -Sometimes getting and storing information about a type at runtime is required. For such cases a construction like `&typeid(T)` or C++11 class `std::type_index` is usually used. And that is the point, where problems start: +Sometimes getting and storing information about a type at runtime is required. For such cases a construction like `&typeid(T)` or C++11 class `std::type_index` is usually used, which is where problems start: * `typeid(T)` and `std::type_index` require Run Time Type Info (RTTI) -* some implementations of `typeid(T)` strip const, volatile and references from type, while others don't +* some implementations of `typeid(T)` erroneously do not strip const, volatile and references from type * some compilers have bugs and do not correctly compare `std::type_info` objects across shared libraries * only a few implementations of Standard Library currently provide `std::type_index` * no easy way to store type info without stripping const, volatile and references @@ -31,7 +31,8 @@ Boost.TypeIndex library was designed to work around all those issues. [section Getting started] -`boost::typeindex::type_info` is a drop-in replacement for `std::type_info` and `boost::typeindex::type_index` +[classref boost::typeindex::type_info boost::typeindex::type_info] is a drop-in replacement for `std::type_info` and +[classref boost::typeindex::type_index boost::typeindex::type_index] is a drop-in replacement for `std::type_index`. Unlike Standard Library versions those classes may work without RTTI. `type_index` provides the full set of comparison operators, hashing functions and ostream @@ -42,43 +43,73 @@ operators, so it can be used with any container class. To start using Boost.TypeIndex: [table:porting -[[Replace this:][With the following:]] +[[Replace this:][With the following:][More Info]] [[`` #include #include ``][`` #include -``]] +``][ + [headerref boost/type_index.hpp more... ] +]] [[`` std::type_index ``][`` boost::typeindex::type_index -``]] +``][ + [classref boost::typeindex::type_index more... ] +]] [[`` typeid(T) - typeid(please_save_modifiers) typeid(T).name() // not human readable typeid(variable) ``][`` boost::typeindex::type_id() - boost::typeindex::type_id_with_cvr() boost::typeindex::type_id().pretty_name() // human readable boost::typeindex::type_id_runtime(variable) -``]] +``][ + [funcref boost::typeindex::type_id more... ] + + [classref boost::typeindex::type_index more... ] + + [funcref boost::typeindex::type_id_runtime more... ] +]] [[`` - const std::type_info& v1 = typeid(int); // when reference to `std::type_info` is required - const std::type_info* v2 = &typeid(int); // other cases + // attempt to save const, volatile, reference + typeid(please_save_modifiers) ``][`` - const boost::typeindex::type_info& v1 = boost::typeindex::type_id().type_info(); - boost::typeindex::type_index v2 = boost::typeindex::type_id(); -``]] + // cvr = const, volatile, reference + boost::typeindex::type_id_with_cvr() +``][ + [funcref boost::typeindex::type_id_with_cvr more... ] +]] + +[[`` + // when reference to `std::type_info` is required + const std::type_info& v1 = typeid(int); + + // other cases + const std::type_info* v2 = &typeid(int); +``][`` + const boost::typeindex::type_info& v1 + = boost::typeindex::type_id().type_info(); + + boost::typeindex::type_index v2 + = boost::typeindex::type_id(); +``][ + [classref boost::typeindex::type_index more... ] + + [funcref boost::typeindex::type_id more... ] +]] ] -If you are using `type_id_runtime()` methods and RTTI is disabled, make sure that classes that are -passed to `type_id_runtime()` are marked with `BOOST_TYPE_INDEX_REGISTER_CLASS` macro. +If you are using [funcref boost::typeindex::type_id_runtime type_id_runtime()] methods +and RTTI is disabled, make sure that classes that are passed to +`type_id_runtime()` are marked with +[macroref BOOST_TYPE_INDEX_REGISTER_CLASS BOOST_TYPE_INDEX_REGISTER_CLASS] macro. [endsect] @@ -171,13 +202,13 @@ public: // visitor interfaces [endsect] [section How it works] -`type_index` is just a typedef for `stl_type_index` or `ctti_type_index`. +`type_index` is just a typedef for [classref boost::typeindex::stl_type_index] +or [classref boost::typeindex::ctti_type_index]. Depending on the `typeid()` availability TypeIndex library will choose an optimal class for -`type_index`. In cases when at least basic support for `typeid()` is available `boost::typeindex::stl_type_index` -will be used. +`type_index`. In cases when at least basic support for `typeid()` is available `stl_type_index` will be used. -`BOOST_TYPE_INDEX_REGISTER_CLASS` macro is a helper macro that places some virtual helper functions or +[macroref BOOST_TYPE_INDEX_REGISTER_CLASS] macro is a helper macro that places some virtual helper functions or expands to nothing. Issues with cross module type comparison on a bugged compilers are bypassed by directly comparing strings with type @@ -206,7 +237,7 @@ Issues with cross module type comparison on a bugged compilers are bypassed by d [xinclude autodoc.xml] -[section Making own type_index] +[section Making a custom type_index] Sometimes there may be a need to create your own type info system. This may be usefull if you wish to store some more info about types (PODness, size of a type, pointers to common functions...) or if you have an idea of a more compact types representations. diff --git a/include/boost/type_index.hpp b/include/boost/type_index.hpp index c55b6f8..b3f917b 100644 --- a/include/boost/type_index.hpp +++ b/include/boost/type_index.hpp @@ -41,7 +41,9 @@ namespace boost { namespace typeindex { /// /// Could be a boost::typeindex::stl_type_index, boost::typeindex::ctti_type_index or /// user defined type_index class. - typedef platform-specific type_index; + /// + /// \b See boost::typeindex::type_index_facade for a full description of type_index functions. + typedef platform_specific type_index; #elif defined(BOOST_TYPE_INDEX_USER_TYPEINDEX) // Nothing to do #elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC) @@ -115,7 +117,7 @@ typedef type_index::type_info_t type_info; #endif // defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) -/// Function to get boost::type_index for a type T. +/// Function to get boost::typeindex::type_index for a type T. /// Removes const, volatile && and & modifiers from T. /// /// \b Example: @@ -132,7 +134,7 @@ inline type_index type_id() BOOST_NOEXCEPT { return type_index::type_id(); } -/// Function for constructing boost::type_index instance for type T. +/// Function for constructing boost::typeindex::type_index instance for type T. /// Does not remove const, volatile, & and && modifiers from T. /// /// If T has no const, volatile, & and && modifiers, then returns exactly diff --git a/include/boost/type_index/type_index_facade.hpp b/include/boost/type_index/type_index_facade.hpp index 02b6e2e..dcb4841 100644 --- a/include/boost/type_index/type_index_facade.hpp +++ b/include/boost/type_index/type_index_facade.hpp @@ -244,13 +244,13 @@ inline bool operator != (const type_index_facade& lhs, const #if defined(BOOST_TYPE_INDEX_DOXYGEN_INVOKED) /// noexcept comparison operators for type_index_facade classes. -bool operator ? (const type_index_facade& lhs, const type_index_facade& rhs) noexcept; +bool operator ==, !=, <, ... (const type_index_facade& lhs, const type_index_facade& rhs) noexcept; /// noexcept comparison operators for type_index_facade and it's TypeInfo classes. -bool operator ? (const type_index_facade& lhs, const TypeInfo& rhs) noexcept; +bool operator ==, !=, <, ... (const type_index_facade& lhs, const TypeInfo& rhs) noexcept; /// noexcept comparison operators for type_index_facade's TypeInfo and type_index_facade classes. -bool operator ? (const TypeInfo& lhs, const type_index_facade& rhs) noexcept; +bool operator ==, !=, <, ... (const TypeInfo& lhs, const type_index_facade& rhs) noexcept; #endif