Boost C++ Libraries Home Libraries People FAQ More

Next

Chapter 1. Boost.TypeIndex 2.1

Distributed under 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)

Table of Contents

Motivation
Getting started
Examples
Getting human readable and mangled type names
Storing information about a type in container
Getting through the inheritance to receive a real type name
Exact type match: storing type with const, volatile and reference
Boost.TypeIndex Header Reference
Header <boost/type_index.hpp>
Header <boost/type_index/type_index.hpp>
Header <boost/type_index/template_index.hpp>
Header <boost/type_index/template_info.hpp>
Header <boost/type_index/type_info.hpp>
Space and Performance
Code bloat
Compiler support
Mixing sources with RTTI on and RTTI off
Acknowledgements

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:

  • 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 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
  • no nice and portable way to get human readable type names

Boost.TypeIndex library was designed to work around all those issues.

[Note] Note

T means type here. Think of it as of T in template <class T>

[Warning] Warning

During the Boost review was decided, that it is better to use interface close to v1.0 of this library. Version 3.0 will attempt to fix all the issues found during the review.

Last revised: January 11, 2014 at 14:36:03 GMT


Next