Metaprogramming:Type name to string

1. Description

MRPT provides a powerful template which allows one to obtain a string representation of any type. The idea is that, for any type T, one can invoke:

This template relies solely on meta-programming techniques (recursive evaluation of templates and partial specializations), and has nothing to do with RTTI or compiler specific extensions. The supported types are:

  • POD (Plain Old Data):  int, float, double, etc…
  • Most MRPT classes: All those derived from mrpt::utils::CSerializable, plus the lightweight geometry structures and more.
  • STL containers.
  • std::pair.
  • Any arbitrarily complex combination of the above.

If you want to extent this mechanism to custom classes or structures (not templates), just use the predefined macro DECLARE_CUSTOM_TTYPENAME:

Extending it to templates requires defining your custom specialization of mrpt::utils::TTypeName<>

2. Examples

The complete example can be found in MRPT/samples/type_name: