Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 /** \example typemeta_TTypeName/test.cpp */
10 
11 //! [example typename]
14 #include <iostream>
15 #include <memory> // shared_ptr
16 
17 // Declare custom user types:
18 struct MyFooClass
19 {
20  using Ptr = std::shared_ptr<MyFooClass>;
21 };
22 namespace MyNS
23 {
24 struct MyBarClass
25 {
26 };
27 struct MyBarClass2
28 {
30 };
31 }
34 
35 void Test_TypeName()
36 {
37  using namespace std;
38  using namespace mrpt::typemeta;
39 
40  // Evaluation of type names as constexpr strings:
41  constexpr auto s1 = TTypeName<int32_t>::get();
42  cout << s1 << endl;
43 
44  cout << TTypeName<set<vector<double>>>::get() << endl;
45 
46  // Evaluation of user-defined types:
47  cout << TTypeName<MyFooClass>::get() << endl;
48  cout << TTypeName<MyFooClass::Ptr>::get() << endl;
49  cout << TTypeName<MyNS::MyBarClass>::get() << endl;
50  cout << TTypeName<MyNS::MyBarClass2>::get() << endl;
51 
52  // STL typenames as strings:
53  cout << TTypeName<double>::get() << endl;
54  cout << TTypeName<vector<double>>::get() << endl;
55  cout << TTypeName<array<int32_t, 5>>::get() << endl;
56  cout << TTypeName<set<double>>::get() << endl;
57  cout << TTypeName<pair<int32_t, pair<int32_t, int32_t>>>::get() << endl;
58  cout << TTypeName<map<double, set<int32_t>>>::get() << endl;
59  cout << TTypeName<set<
60  multimap<double, pair<MyFooClass, MyNS::MyBarClass2>>>>::get()
61  << endl;
62 }
63 //! [example typename]
64 
65 int main(int argc, char** argv)
66 {
67  try
68  {
69  Test_TypeName();
70  return 0;
71  }
72  catch (std::exception& e)
73  {
74  std::cout << "Exception: " << e.what() << std::endl;
75  return -1;
76  }
77 }
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