Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.


Header <boost/core/type_name.hpp>


  • Peter Dimov

The header <boost/core/type_name.hpp> defines the function template boost::core::type_name<T>() that returns a string representation of the name of T, suitable for logging or diagnostic display purposes.

The result is similar to boost::core::demangle( typeid(T).name() ), but it's made more regular by eliminating some of the platform-specific differences and extra template parameters of the standard library container types.

For example, type_name< std::map<std::string, int> >() returns "std::map<std::string, int>" and not

std::map<std::__cxx11::basic_string<char, std::char_traits<char>,
  std::allocator<char> >, int, std::less<std::__cxx11::basic_string<char,
  std::char_traits<char>, std::allocator<char> > >, std::allocator<
  std::pair<std::__cxx11::basic_string<char, std::char_traits<char>,
  std::allocator<char> > const, int> > >


class std::map<class std::basic_string<char,struct std::char_traits<char>,
  class std::allocator<char> >,int,struct std::less<class std::basic_string<
  char,struct std::char_traits<char>,class std::allocator<char> > >,class
  std::allocator<struct std::pair<class std::basic_string<char,struct
  std::char_traits<char>,class std::allocator<char> > const ,int> > >

The return values aren't guaranteed to be stable across Boost releases.

Compilation with -fno-rtti is supported, but the returned type names aren't guaranteed to be particularly useful or unique.

namespace boost
namespace core

template<class T> std::string type_name();

} // namespace core
} // namespace boost
  • Returns: A string representation of the name of T.