MRPT  1.9.9
typemeta_StaticString/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_StaticString/test.cpp */
//! [example sstring]
#include <iostream>
{
using namespace std;
using namespace mrpt::typemeta;
constexpr string_literal<3> s = "foo";
cout << "string_literal<3>=" << s << endl;
constexpr auto a = literal("foo");
constexpr auto b = literal("bar");
// In GCC7 this can be "constexpr", but it fails in MSVC 2017 (!)
auto ab = a + b;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "a+b=" << ab << endl;
static_assert(ab.size() == 6, "***");
cout << "(a+b).size()=" << ab.size() << endl;
cout << "(a+b)[0]=" << ab[0] << endl;
cout << "(a+b)[5]=" << ab[5] << endl;
}
//! [example sstring]
//! [example num2str]
#include <iostream>
{
using namespace std;
using namespace mrpt::typemeta;
constexpr auto n42 = num_to_string<42>::value;
constexpr auto n9999 = num_to_string<9999>::value;
cout << "42 as string=" << n42 << endl;
cout << "9999 as string=" << n9999 << endl;
}
//! [example num2str]
int main(int argc, char** argv)
{
try
{
return 0;
}
catch (std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
return -1;
}
}



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020