# Boost.TypeIndex Header Reference

Includes minimal set of headers required to use the Boost.TypeIndex library.

By inclusion of this file most optimal type index classes will be included and used as a boost::typeindex::type_index and boost::typeindex::type_info.

Depending on a compiler flags, optimal implementation of type_index will be used as a default boost::typeindex::type_index.

Could be a `boost::typeindex::stl_type_index`, `boost::typeindex::ctti_type_index` or user defined type_index class.

See `boost::typeindex::type_index_facade` for a full description of type_index functions.

platform_specific

Depending on a compiler flags, optimal implementation of type_info will be used as a default boost::typeindex::type_info.

Could be a std::type_info, `boost::typeindex::detail::ctti_data` or some user defined class.

type_info is not copyable or default constructible. It is not assignable too!

type_index::type_info_t
type_index

Type for which type_index must be created.

Function to get boost::typeindex::type_index for a type T. Removes const, volatile && and & modifiers from T.

Example:

     type_index ti = type_id<int&>();
     std::cout << ti.pretty_name();  // Outputs 'int'

boost::typeindex::type_index with information about the specified type T.

`Nothing.`

type_index

Type for which type_index must be created.

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 the same result as in case of calling `type_id<T>()`.

Example:

     type_index ti = type_id_with_cvr<int&>();
     std::cout << ti.pretty_name();  // Outputs 'int&'

boost::typeindex::type_index with information about the specified type T.

`Nothing.`

type_index `const T &

Varaible which runtime type must be returned.

`

Function that works exactly like C++ typeid(rtti_val) call, but returns boost::type_index.

Retunrs runtime information about specified type.

Requirements: RTTI available or Base and Derived classes must be marked with BOOST_TYPE_INDEX_REGISTER_CLASS.

Example:

     struct Base { virtual ~Base(){} };
     struct Derived: public Base  {};
     ...
     Derived d;
     Base& b = d;
     type_index ti = type_id_runtime(b);
     std::cout << ti.pretty_name();  // Outputs 'Derived'

boost::typeindex::type_index with information about the specified variable.

`Nothing.`

BOOST_TYPE_INDEX_REGISTER_CLASS is 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 `virtual const type_info& boost_type_info_type_id_runtime_() const noexcept`.

Example:

     class A {
     public:
         BOOST_TYPE_INDEX_REGISTER_CLASS
         virtual ~A(){}
     };

     struct B: public A {
         BOOST_TYPE_INDEX_REGISTER_CLASS
     };

     struct C: public B {
         BOOST_TYPE_INDEX_REGISTER_CLASS
     };

     ...

     C c1;
     A* pc1 = &c1;
     assert(boost::typeindex::type_id<C>() == boost::typeindex::type_id_runtime(*pc1));

BOOST_TYPE_INDEX_FUNCTION_SIGNATURE is used by `boost::typeindex::ctti_type_index` class to deduce the name of a type. If your compiler is not recognized by the TypeIndex library and you wish to work with `boost::typeindex::ctti_type_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::typeindex::ctti_type_index` classes.

See BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS and BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING for an information of how to tune the implementation to make a nice pretty_name() output.

This is a helper macro for making correct pretty_names() with RTTI off.

BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING macro may be defined to '(begin_skip, end_skip, runtime_skip, runtime_skip_until)' with parameters for adding a support for compilers, that by default are not recognized by TypeIndex library.

Example:

Imagine the situation when

     boost::typeindex::ctti_type_index::type_id<int>().pretty_name()

returns the following string:

     "static const char *boost::detail::ctti<int>::n() [T = int]"

and

     boost::typeindex::ctti_type_index::type_id<short>().pretty_name()

returns the following:

     "static const char *boost::detail::ctti<short>::n() [T = short]"

As we may see first 39 characters are "static const char *boost::detail::ctti<" and they do not depend on the type T. After first 39 characters we have a human readable type name which is duplicated at the end of a string. String always ends on ']', which consumes 1 character.

Now if we define `BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING` to `(39, 1, false, "")` we'll be getting

     "int>::n() [T = int"

for `boosttypeindex::ctti_type_index::type_id<int>().pretty_name()` and

     "short>::n() [T = short"

for `boosttypeindex::ctti_type_index::type_id<short>().pretty_name()`.

Now we need to take additional care of the characters that go before the last mention of our type. We'll do that by telling the macro that we need to cut off everything that goes before the "T = " including the "T = " itself:

     (39, 1, true, "T = ")

In case of GCC or Clang command line we need to add the following line while compiling all the sources:

     -DBOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING='(39, 1, true, "T = ")'

See [RTTI emulation limitations](boost_typeindex/rtti_emulation_limitations.html) for more info.

BOOST_TYPE_INDEX_USER_TYPEINDEX can be defined to the path to header file with user provided implementation of type_index.

See [Making a custom type_index](boost_typeindex/making_a_custom_type_index.html) section of documentation for usage example.

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](boost_typeindex/mixing_sources_with_rtti_on_and_.html) section of documentation for more info.

Contains `boost::typeindex::ctti_type_index` class.

`boost::typeindex::ctti_type_index` class can be used as a drop-in replacement for std::type_index.

It is used in situations when typeid() method is not available or BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY macro is defined.

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` in situations when typeid() is working.

unspecified
std::size_t
const `type_info_t` &

Override: This function may be redefined in Derived class. Overrides must not throw.

Const reference to underlying low level type_info_t.

const char *

Override: This function must be redefined in Derived class. Overrides must not throw.

Pointer to unredable/raw type name.

std::string

Override: This function may be redefined in Derived class. Overrides may throw.

Human readable type name. By default returns Derived::name().

std::size_t

Override: This function may be redefined in Derived class. Overrides must not throw.

<boost/functional/hash.hpp> has to be included if this function is used.

Hash code of a type. By default hashes types by raw_name().

const `type_info_t` &
`ctti_type_index`

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must remove const, volatile && and & modifiers from T.

type_index for type T.

`ctti_type_index`

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_with_cvr() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must not remove const, volatile && and & modifiers from T.

type_index for type T.

`ctti_type_index` `const T &

Variable which runtime type will be stored in type_index.

`

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_runtime(const T&) will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class.

type_index with runtime type of variable.

unspecified Helper method for getting `detail::ctti_data` of a template parameter T.

Contains `boost::typeindex::stl_type_index` class.

`boost::typeindex::stl_type_index` class can be used as a drop-in replacement for std::type_index.

It is used in situations when RTTI is enabled or typeid() method is available. When typeid() is disabled or BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY macro is defined boost::typeindex::ctti is usually used instead of `boost::typeindex::stl_type_index`.

boost::typeindex::type_index_facade< stl_type_index, std::type_info >

This class is a wrapper around std::type_info, that workarounds issues and provides much more rich interface. For description of functions see `type_index_facade`.

This class requires typeid() to work. For cases when RTTI is disabled see `ctti_type_index`.

std::type_info
const type_info_t &

Override: This function may be redefined in Derived class. Overrides must not throw.

Const reference to underlying low level type_info_t.

const char *

Override: This function must be redefined in Derived class. Overrides must not throw.

Pointer to unredable/raw type name.

const char *

Override: This function may be redefined in Derived class. Overrides must not throw.

Name of a type. By default returns Derived::raw_name().

std::string

Override: This function may be redefined in Derived class. Overrides may throw.

Human readable type name. By default returns Derived::name().

std::size_t

Override: This function may be redefined in Derived class. Overrides must not throw.

<boost/functional/hash.hpp> has to be included if this function is used.

Hash code of a type. By default hashes types by raw_name().

bool `const `stl_type_index` &`

Override: This function may be redefined in Derived class. Overrides must not throw.

True if two types are equal. By default compares types by raw_name().

bool `const `stl_type_index` &`

Override: This function may be redefined in Derived class. Overrides must not throw.

True if rhs is greater than this. By default compares types by raw_name().

const type_info_t &
`stl_type_index`

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must remove const, volatile && and & modifiers from T.

type_index for type T.

`stl_type_index`

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_with_cvr() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must not remove const, volatile && and & modifiers from T.

type_index for type T.

`stl_type_index` `const T &

Variable which runtime type will be stored in type_index.

`

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_runtime(const T&) will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class.

type_index with runtime type of variable.

Class derived from `type_index_facade`.

Class that will be used as a base type_info class.

This class takes care about the comparison operators, hash functions and ostream operators. Use this class as a public base class for defining new type_info-conforming classes.

Example:

     class stl_type_index: public type_index_facade<stl_type_index, std::type_info>
     {
     public:
         typedef std::type_info type_info_t;
     private:
         const type_info_t* data_;

     public:
         stl_type_index(const type_info_t& data) noexcept
             : data_(&data)
         {}
     // ...
     };

Take a look at the protected methods. They are not defined in `type_index_facade`. Protected member functions raw_name() must be defined in Derived class. All the other methods are mandatory.

See Also:

'Making a custom type_index' section for more information about creating your own type_index using `type_index_facade`.

TypeInfo
const char *

Override: This function may be redefined in Derived class. Overrides must not throw.

Name of a type. By default returns Derived::raw_name().

std::string

Override: This function may be redefined in Derived class. Overrides may throw.

Human readable type name. By default returns Derived::name().

bool `const Derived &`

Override: This function may be redefined in Derived class. Overrides must not throw.

True if two types are equal. By default compares types by raw_name().

bool `const Derived &`

Override: This function may be redefined in Derived class. Overrides must not throw.

True if rhs is greater than this. By default compares types by raw_name().

std::size_t

Override: This function may be redefined in Derived class. Overrides must not throw.

<boost/functional/hash.hpp> has to be included if this function is used.

Hash code of a type. By default hashes types by raw_name().

const char *

Override: This function must be redefined in Derived class. Overrides must not throw.

Pointer to unredable/raw type name.

const type_info_t &

Override: This function may be redefined in Derived class. Overrides must not throw.

Const reference to underlying low level type_info_t.

Derived

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must remove const, volatile && and & modifiers from T.

type_index for type T.

Derived

Type for which type_index must be created.

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_with_cvr() will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class. Overrides must not throw. Overrides must not remove const, volatile && and & modifiers from T.

type_index for type T.

Derived `const T &

Variable which runtime type will be stored in type_index.

`

This is a factory method that is used to create instances of Derived classes. boost::typeindex::type_id_runtime(const T&) will call this method, if Derived has same type as boost::typeindex::type_index.

Override: This function may be redefined and made public in Derived class.

type_index with runtime type of variable.

bool `const `type_index_facade` &` `const `type_index_facade` &`

noexcept comparison operators for `type_index_facade` classes.

bool `const `type_index_facade` &` `const TypeInfo &` noexcept comparison operators for `type_index_facade` and it's TypeInfo classes.
bool `const TypeInfo &` `const `type_index_facade` &` noexcept comparison operators for `type_index_facade`'s TypeInfo and `type_index_facade` classes.
std::basic_ostream< CharT, TriatT > & `std::basic_ostream< CharT, TriatT > &` `const `type_index_facade`< Derived, TypeInfo > &` Ostream operator that will output demangled name.
std::size_t `const `type_index_facade`< Derived, TypeInfo > &`

This free function is used by Boost's unordered containers.

<boost/functional/hash.hpp> has to be included if this function is used.

std::size_t `It` `It`