Main MRPT website > C++ reference for MRPT 1.9.9
typemeta_TTypeName/test.cpp
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| http://www.mrpt.org/ |
| |
| Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
| See: http://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See details in http://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
/** \example typemeta_TTypeName/test.cpp */
//! [example typename]
#include <iostream>
#include <memory> // shared_ptr
// Declare custom user types:
struct MyFooClass
{
using Ptr = std::shared_ptr<MyFooClass>;
};
namespace MyNS
{
struct MyBarClass
{
};
struct MyBarClass2
{
};
}
{
using namespace std;
using namespace mrpt::typemeta;
// Evaluation of type names as constexpr strings:
constexpr auto s1 = TTypeName<int32_t>::get();
cout << s1 << endl;
cout << TTypeName<set<vector<double>>>::get() << endl;
// Evaluation of user-defined types:
cout << TTypeName<MyFooClass>::get() << endl;
cout << TTypeName<MyFooClass::Ptr>::get() << endl;
cout << TTypeName<MyNS::MyBarClass>::get() << endl;
cout << TTypeName<MyNS::MyBarClass2>::get() << endl;
// STL typenames as strings:
cout << TTypeName<double>::get() << endl;
cout << TTypeName<vector<double>>::get() << endl;
cout << TTypeName<array<int32_t, 5>>::get() << endl;
cout << TTypeName<set<double>>::get() << endl;
cout << TTypeName<pair<int32_t, pair<int32_t, int32_t>>>::get() << endl;
cout << TTypeName<map<double, set<int32_t>>>::get() << endl;
cout << TTypeName<set<
multimap<double, pair<MyFooClass, MyNS::MyBarClass2>>>>::get()
<< endl;
}
//! [example typename]
int main(int argc, char** argv)
{
try
{
return 0;
}
catch (std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
}
Test_TypeName
void Test_TypeName()
Definition: vision_stereo_rectify/test.cpp:35
mrpt::typemeta
Definition: config/CConfigFileBase.h:21
MyNS
[example-define-class]
Definition: rtti_unittest.cpp:13
MyNS::MyBarClass2
Definition: typename_unittest.cpp:25
MyNS::MyBarClass
Definition: typename_unittest.cpp:22
mrpt::typemeta::TTypeName
A template to obtain the type of its argument as a string at compile time.
Definition: TTypeName.h:65
DECLARE_TTYPENAME_CLASSNAME
#define DECLARE_TTYPENAME_CLASSNAME(_CLASSNAME)
Like DECLARE_CUSTOM_TTYPENAME(), but for use within the class declaration body.
Definition: TTypeName.h:100
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
TTypeName.h
MyFooClass::Ptr
std::shared_ptr< MyFooClass > Ptr
Definition: typename_unittest.cpp:18
DECLARE_CUSTOM_TTYPENAME
#define DECLARE_CUSTOM_TTYPENAME(_TYPE)
Identical to MRPT_DECLARE_TTYPENAME but intended for user code.
Definition: TTypeName.h:86
MyFooClass
[example typename]
Definition: typename_unittest.cpp:16
TTypeName_stl.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST