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_StaticString/test.cpp */
10 
11 //! [example sstring]
13 #include <iostream>
14 
15 void Test_StaticString()
16 {
17  using namespace std;
18  using namespace mrpt::typemeta;
19 
20  constexpr string_literal<3> s = "foo";
21  cout << "string_literal<3>=" << s << endl;
22 
23  constexpr auto a = literal("foo");
24  constexpr auto b = literal("bar");
25  // In GCC7 this can be "constexpr", but it fails in MSVC 2017 (!)
26  auto ab = a + b;
27  cout << "a=" << a << endl;
28  cout << "b=" << b << endl;
29  cout << "a+b=" << ab << endl;
30 
31  static_assert(ab.size() == 6, "***");
32  cout << "(a+b).size()=" << ab.size() << endl;
33  cout << "(a+b)[0]=" << ab[0] << endl;
34  cout << "(a+b)[5]=" << ab[5] << endl;
35 }
36 //! [example sstring]
37 
38 //! [example num2str]
40 #include <iostream>
41 
42 void Test_StaticNum2Str()
43 {
44  using namespace std;
45  using namespace mrpt::typemeta;
46 
47  constexpr auto n42 = num_to_string<42>::value;
48  constexpr auto n9999 = num_to_string<9999>::value;
49  cout << "42 as string=" << n42 << endl;
50  cout << "9999 as string=" << n9999 << endl;
51 }
52 //! [example num2str]
53 
54 int main(int argc, char** argv)
55 {
56  try
57  {
59  return 0;
60  }
61  catch (std::exception& e)
62  {
63  std::cout << "Exception: " << e.what() << std::endl;
64  return -1;
65  }
66 }
Test_StaticNum2Str
void Test_StaticNum2Str()
[example sstring]
Definition: vision_stereo_rectify/test.cpp:42
mrpt::typemeta
Definition: config/CConfigFileBase.h:21
s
GLdouble s
Definition: glext.h:3676
num_to_string.h
mrpt::typemeta::num_to_string
constexpr string representation of a number.
Definition: num_to_string.h:44
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::typemeta::string_literal
Definition: static_string.h:23
b
GLubyte GLubyte b
Definition: glext.h:6279
Test_StaticString
void Test_StaticString()
[example sstring]
Definition: vision_stereo_rectify/test.cpp:15
static_string.h
mrpt::typemeta::literal
constexpr auto literal(const char(&lit)[N_PLUS_1]) -> string_literal< N_PLUS_1 - 1 >
Definition: static_string.h:43
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



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