Updated docs and fixed some issues

This commit is contained in:
Antony Polukhin
2013-10-28 17:16:19 +04:00
parent 8ab45702a0
commit d0d30d56df
5 changed files with 50 additions and 53 deletions

View File

@@ -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

View File

@@ -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 <boost/config.hpp>
#include <boost/type_index/type_info.hpp>
@@ -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<const type_info*>(&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<const type_info*>(&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)

View File

@@ -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 <class T>
@@ -135,18 +136,19 @@ public:
return static_cast<const boost::type_info&>(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<const detail::stl_type_info&>(*this) == static_cast<const detail::stl_type_info&>(rhs);
return static_cast<const stl_type_info&>(*this) == static_cast<const stl_type_info&>(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<const boost::type_info&>(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<const boost::type_info&>(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 <class T>
inline const type_info& type_id() BOOST_NOEXCEPT {
return type_info::construct<T>();
@@ -243,7 +250,7 @@ inline const type_info& type_id_with_cvr() BOOST_NOEXCEPT {
return type_info::construct_with_cvr<T>();
}
/// 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 <class T>
@@ -251,7 +258,7 @@ inline const type_info& type_id_rtti_only(T& rtti_val) BOOST_NOEXCEPT {
return static_cast<const type_info&>(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 <class T>

View File

@@ -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
<doxygen:param>ENABLE_PREPROCESSING=YES
<doxygen:param>EXPAND_ONLY_PREDEF=YES
<doxygen:param>MACRO_EXPANSION=YES
<doxygen:param>"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<a, b> &&\" \\
\"BOOST_RV_REF_3_TEMPL_ARGS(T,a,b,c)=T<a,b,c>T<a,b,c> &&\" \\
\"BOOST_FWD_REF(a)=a &&\""
<doxygen:param>"PREDEFINED=\"stl_type_info=std::type_info\" \\
\"detail::stl_type_info=std::type_info\""
<xsl:param>"boost.doxygen.reftitle=Boost.TypeIndex Header Reference"
;

View File

@@ -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 `<boost/type_index/type_index.hpp>` instead of `<typeindex>`
* Use `<boost/type_index/type_info.hpp>` instead of `<typeinfo>`
* 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<T>()` instead of `typeid(T)`, `&typeid(T)`.
* If you want to save `const`, `volatile`, `&` and `&&`:
* Use `boost::type_id_with_cvr<T>()` instead of `typeid(T)`, `&typeid(T)`.
* To get nice human readable names, use the `name_demangled()` member function:
``
#include <boost/type_index/type_index_minimal.hpp>
#include <boost/type_index.hpp>
type_index ti = type_id<T>();
std::string nice_name