From d0d30d56dfe82396de409db99d2ead940fd121a7 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 28 Oct 2013 17:16:19 +0400 Subject: [PATCH] Updated docs and fixed some issues --- boost/type_index.hpp | 2 +- boost/type_index/type_index.hpp | 37 ++++++++++++---------------- boost/type_index/type_info.hpp | 39 ++++++++++++++++++------------ libs/type_index/doc/Jamfile.v2 | 14 +++-------- libs/type_index/doc/type_index.qbk | 11 ++++++--- 5 files changed, 50 insertions(+), 53 deletions(-) diff --git a/boost/type_index.hpp b/boost/type_index.hpp index 3ad0f09..3bebe59 100644 --- a/boost/type_index.hpp +++ b/boost/type_index.hpp @@ -8,7 +8,7 @@ #ifndef BOOST_TYPE_INDEX_HPP #define BOOST_TYPE_INDEX_HPP -/// \file type_index.hpp +/// \file boost/type_index.hpp /// \brief Includes all the headers of the Boost.TypeIndex library. /// /// By inclusion of this file all classes (boost::type_info + boost::type_index if RTTI is on diff --git a/boost/type_index/type_index.hpp b/boost/type_index/type_index.hpp index f678c56..fc10d27 100644 --- a/boost/type_index/type_index.hpp +++ b/boost/type_index/type_index.hpp @@ -13,10 +13,12 @@ # pragma once #endif -/// \file type_index.hpp +/// \file boost/type_index/type_index.hpp /// \brief Contains implementation of boost::type_index class. /// /// boost::type_index class is used in situations when RTTI is enabled. +/// When RTTI is disabled boost::template_index will be used instead of +/// this class. #include #include @@ -33,12 +35,16 @@ namespace boost { -/// Copyable type_index class that requires RTTI. +/// Copyable std::type_index class that requires RTTI. +/// When RTTI is disabled boost::template_index will be used instead of +/// this class. class type_index { private: const type_info* pinfo_; public: + typedef detail::stl_type_info stl_type_info; + /// Default constructor. type_index() BOOST_NOEXCEPT : pinfo_(static_cast(&typeid(void))) @@ -50,7 +56,7 @@ public: {} /// Constructs type_index from an instance of std::type_info. - type_index(const detail::stl_type_info& inf) BOOST_NOEXCEPT + type_index(const stl_type_info& inf) BOOST_NOEXCEPT : pinfo_(static_cast(&inf)) {} @@ -70,7 +76,6 @@ public: return pinfo_->name_demangled(); } -#ifndef BOOST_TYPE_INDEX_DOXYGEN_INVOKED bool operator == (type_index const& rhs) const BOOST_NOEXCEPT { return *pinfo_ == *rhs.pinfo_; } @@ -96,30 +101,30 @@ public: } - bool operator == (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator == (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this == type_index(rhs); } - bool operator != (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator != (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this != type_index(rhs); } - bool operator < (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator < (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this < type_index(rhs); } - bool operator > (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator > (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this > type_index(rhs); } - bool operator <= (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator <= (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this <= type_index(rhs); } - bool operator >= (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator >= (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this >= type_index(rhs); } -#endif // BOOST_TYPE_INDEX_DOXYGEN_INVOKED + /// Function for getting hash value std::size_t hash_code() const BOOST_NOEXCEPT { @@ -127,8 +132,6 @@ public: } }; -#ifndef BOOST_TYPE_INDEX_DOXYGEN_INVOKED - /* *************** type_index free functions ******************* */ inline bool operator == (detail::stl_type_info const& lhs, type_index const& rhs) BOOST_NOEXCEPT { @@ -155,18 +158,12 @@ inline bool operator >= (detail::stl_type_info const& lhs, type_index const& rhs return rhs <= lhs; } -#endif // BOOST_TYPE_INDEX_DOXYGEN_INVOKED - #ifdef BOOST_CLASSINFO_COMPARE_BY_NAMES #undef BOOST_CLASSINFO_COMPARE_BY_NAMES #endif -/// @endcond - /* *************** type_index free functions ******************* */ -/// @cond - #ifndef BOOST_NO_IOSTREAM #ifdef BOOST_NO_TEMPLATED_IOSTREAMS @@ -193,8 +190,6 @@ inline std::size_t hash_value(type_index const& v) BOOST_NOEXCEPT { return v.hash_code(); } -/// @endcond - } // namespace boost #else // !defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NORTTI_COMPATIBILITY) diff --git a/boost/type_index/type_info.hpp b/boost/type_index/type_info.hpp index 94bcd43..ddc5bcf 100644 --- a/boost/type_index/type_info.hpp +++ b/boost/type_index/type_info.hpp @@ -51,11 +51,10 @@ namespace boost { -#ifndef BOOST_TYPE_INDEX_DOXYGEN_INVOKED +/// @cond // for this compiler at least, cross-shared-library type_info -// comparisons don't work, so use typeid(x).name() instead. It's not -// yet clear what the best default strategy is. +// comparisons don't work, so we are using typeid(x).name() instead. # if (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5))) \ || defined(_AIX) \ || (defined(__sgi) && defined(__host_mips)) \ @@ -64,7 +63,7 @@ namespace boost { # define BOOST_CLASSINFO_COMPARE_BY_NAMES # endif -#endif // BOOST_TYPE_INDEX_DOXYGEN_INVOKED +/// @endcond namespace detail { #ifdef BOOST_NO_STD_TYPEINFO @@ -88,6 +87,8 @@ namespace detail { /// * workarounds some cimpiler issues class type_info: public detail::stl_type_info { public: + typedef detail::stl_type_info stl_type_info; + /// Factory method for constructing boost::type_info instance for type T. /// Strips const, volatile and & modifiers from T. template @@ -135,18 +136,19 @@ public: return static_cast(typeid(rtti_val)); } + /// Returns mangled type name. const char* name() const BOOST_NOEXCEPT { #ifdef _MSC_VER - return detail::stl_type_info::raw_name(); + return stl_type_info::raw_name(); #else - return detail::stl_type_info::name(); + return stl_type_info::name(); #endif } /// Returns user-friendly name std::string name_demangled() const { #if defined(_MSC_VER) - std::string ret = detail::stl_type_info::name(); + std::string ret = stl_type_info::name(); #else std::string ret; int status = 0; @@ -184,7 +186,7 @@ public: #ifdef BOOST_CLASSINFO_COMPARE_BY_NAMES return !std::strcmp(name(), rhs.name()); #else - return static_cast(*this) == static_cast(rhs); + return static_cast(*this) == static_cast(rhs); #endif } @@ -192,32 +194,36 @@ public: return !(*this == rhs); } - bool operator == (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator == (stl_type_info const& rhs) const BOOST_NOEXCEPT { return *this == static_cast(rhs); } - bool operator != (detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + bool operator != (stl_type_info const& rhs) const BOOST_NOEXCEPT { return !(*this == rhs); } /// Returns true if the type precedes the type of rhs in the collation order. /// The collation order is just an internal order. + /// Works exactly like operator < bool before(type_info const& rhs) const BOOST_NOEXCEPT { #ifdef BOOST_CLASSINFO_COMPARE_BY_NAMES return std::strcmp(name(), rhs.name()) < 0; #else - return detail::stl_type_info::before(rhs); + return stl_type_info::before(rhs); #endif } - bool before(detail::stl_type_info const& rhs) const BOOST_NOEXCEPT { + /// Returns true if the type precedes the type of rhs in the collation order. + /// The collation order is just an internal order. + /// Works exactly like operator < + bool before(stl_type_info const& rhs) const BOOST_NOEXCEPT { return before(static_cast(rhs)); } /// Function for getting hash value std::size_t hash_code() const BOOST_NOEXCEPT { #if _MSC_VER >= 1600 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__)) - return detail::stl_type_info::hash_code(); + return stl_type_info::hash_code(); #else return boost::hash_range(name(), name() + std::strlen(name())); #endif @@ -228,7 +234,8 @@ public: #undef BOOST_CLASSINFO_COMPARE_BY_NAMES #endif -/// Function, to get std::type_info for a type T. Strips const, volatile and & modifiers from T. +/// Function to get std::type_info for a type T. +/// Strips const, volatile and & modifiers from T. template inline const type_info& type_id() BOOST_NOEXCEPT { return type_info::construct(); @@ -243,7 +250,7 @@ inline const type_info& type_id_with_cvr() BOOST_NOEXCEPT { return type_info::construct_with_cvr(); } -/// Function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_info. +/// Function that works exactly like C++ typeid(rtti_val) call, but returns boost::type_info. /// This method available only with RTTI enabled. Without RTTI support it won't compile, /// producing a compile-time error with message: "boost::type_id_rtti_only(T&) requires RTTI" template @@ -251,7 +258,7 @@ inline const type_info& type_id_rtti_only(T& rtti_val) BOOST_NOEXCEPT { return static_cast(typeid(rtti_val)); } -/// Function, that works exactly like C++ typeid(rtti_val) call, but returns boost::type_info. +/// Function that works exactly like C++ typeid(rtti_val) call, but returns boost::type_info. /// This method available only with RTTI enabled. Without RTTI support it won't compile, /// producing a compile-time error with message: "boost::type_id_rtti_only(T*) requires RTTI" template diff --git a/libs/type_index/doc/Jamfile.v2 b/libs/type_index/doc/Jamfile.v2 index 18cf11c..fb44471 100644 --- a/libs/type_index/doc/Jamfile.v2 +++ b/libs/type_index/doc/Jamfile.v2 @@ -1,4 +1,4 @@ -# Copyright Antony Polukhin 2011. +# Copyright Antony Polukhin 2011-2013. # Use, modification, and distribution are # subject to the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,16 +18,8 @@ doxygen autodoc ENABLE_PREPROCESSING=YES EXPAND_ONLY_PREDEF=YES MACRO_EXPANSION=YES - "PREDEFINED=\"insert_const_ref_type= const T&\" \\ - \"BOOST_TYPE_INDEX_DOXYGEN_INVOKED\" \\ - \"BOOST_RV_REF(T)=T &&\" \\ - \"BOOST_RV_REF_BEG=\" \\ - \"BOOST_RV_REF_END=&&\" \\ - \"BOOST_CLASSINFO_COMPARISON_NOEXCEPT=\" \\ - \"BOOST_COPY_ASSIGN_REF(T)=const T &\" \\ - \"BOOST_RV_REF_2_TEMPL_ARGS(T,a,b)=T &&\" \\ - \"BOOST_RV_REF_3_TEMPL_ARGS(T,a,b,c)=TT &&\" \\ - \"BOOST_FWD_REF(a)=a &&\"" + "PREDEFINED=\"stl_type_info=std::type_info\" \\ + \"detail::stl_type_info=std::type_info\"" "boost.doxygen.reftitle=Boost.TypeIndex Header Reference" ; diff --git a/libs/type_index/doc/type_index.qbk b/libs/type_index/doc/type_index.qbk index ba21465..4d22c5f 100644 --- a/libs/type_index/doc/type_index.qbk +++ b/libs/type_index/doc/type_index.qbk @@ -1,6 +1,6 @@ [library Boost.TypeIndex - [quickbook 1.5] - [version 1.0] + [quickbook 1.6] + [version 2.0] [copyright 2012-2013 Antony Polukhin] [category Language Features Emulation] [license @@ -36,14 +36,17 @@ hashing functions and ostream operators, so it can be used with any container cl To start using it: -* Replace `std::type_index`, `const std::type_info&`, `const std::type_info*` with `boost::type_index`. +* Replace headers: + * Use `` instead of `` + * Use `` instead of `` +* Replace `std::type_index`, `const std::type_info&` and `const std::type_info*` variables with `boost::type_index`. * If you do not want to save `const`, `volatile`, `&` and `&&`: * Use `boost::type_id()` instead of `typeid(T)`, `&typeid(T)`. * If you want to save `const`, `volatile`, `&` and `&&`: * Use `boost::type_id_with_cvr()` instead of `typeid(T)`, `&typeid(T)`. * To get nice human readable names, use the `name_demangled()` member function: `` -#include +#include type_index ti = type_id(); std::string nice_name