MRPT provides a powerful template which allows one to obtain a string representation of any type:
{syntaxhighlighter brush: cpp}
template
struct TTypeName
{
static std::string get();
};
{/syntaxhighlighter}
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:
The complete example can be found in MRPT/samples/type_name.
{syntaxhighlighter brush: cpp}
#include
#include
using namespace mrpt;
using namespace mrpt::utils;
using namespace mrpt::poses;
using namespace mrpt::slam;
using namespace std;
...
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
cout << "Type: " << TTypeName
{/syntaxhighlighter}
And the output is:
{syntaxhighlighter brush: plain}
Type: int32_t
Type: double
Type: CPose2D
Type: COccupancyGridMap2D
Type: std::vector
Type: std::set
Type: std::set
Type: std::pair
Type: std::pair
Type: std::map
Type: std::set
{/syntaxhighlighter}