Main MRPT website > C++ reference for MRPT 1.9.9
static_string_unittest.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 
12 #include <gtest/gtest.h>
13 
14 using namespace mrpt::typemeta;
15 
16 TEST(StaticString, ctor)
17 {
18  constexpr string_literal<3> a = "foo";
19  (void)(a);
20 
21  constexpr auto b = literal("foo");
22  (void)(b);
23 }
24 
25 TEST(StaticString, concat_literals)
26 {
27  constexpr auto a = literal("foo");
28  constexpr auto b = literal("bar");
29  // In GCC7 these ones can be "constexpr", but that fails in MSVC 2017 (!)
30  auto ab = a + b;
31 
32  static_assert(ab.size() == 6, "***");
33  EXPECT_EQ(ab[0], 'f');
34  EXPECT_EQ(ab[5], 'r');
35 }
36 
37 TEST(StaticString, concat_multi)
38 {
39  constexpr auto a = literal("foo");
40  constexpr auto b = literal("bar");
41  auto ab = a + b;
42  auto ba = b + a;
43 
44  // test sstring + literal:
45  auto abc = ab + literal("more");
46  static_assert(abc.size() == (6 + 4), "***");
47 
48  // test sstring + sstring:
49  auto abba = ab + ba;
50  static_assert(abba.size() == 2 * 6, "***");
51 
52  const char* s = abba.c_str();
53  (void)(s);
54 }
55 
57 {
58  constexpr auto a = num_to_string<13>::value;
59  (void)(a);
60 }
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
mrpt::typemeta::string_literal
Definition: static_string.h:23
b
GLubyte GLubyte b
Definition: glext.h:6279
void
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
static_string.h
TEST
TEST(StaticString, ctor)
Definition: static_string_unittest.cpp:16
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