template struct mrpt::typemeta::TTypeName

A template to obtain the type of its argument as a string at compile time.

It works with all classes derived from CObject, plus many specializations for the plain data types (bool, double, uint8_t, etc…) For example:

cout << TTypeName<double>::get() << endl;  // "double"
cout << TTypeName<CPose2D>::get() << endl; // "CPose2D"

Users can extend this for custom structs/classes with the macro DECLARE_CUSTOM_TTYPENAME:

class MyClass { ... };
DECLARE_CUSTOM_TTYPENAME(MyClass)
cout << TTypeName<MyClass>::get() << endl;  // "MyClass"

or alternatively, to avoid adding out-of-class macros:

namespace MyNS {
 class MyClass {
   DECLARE_TTYPENAME_CLASSNAME(MyNS::MyClass)
 };
}
cout << TTypeName<MyNS::MyClass>::get() << endl; // "MyNS::MyClass"

The following types are NOT ALLOWED since they have platform-dependant sizes:

  • int, unsigned int

  • long, unsigned long

  • short, unsigned short

  • size_t

#include <mrpt/typemeta/TTypeName.h>

template <typename T>
struct TTypeName
{
    //
methods

    static constexpr auto get();
};