Commit 7d48b446b32b762074e0de6d8f22311a88c5c8ef

Authored by Jay Berkenbilt
1 parent c60b4ea5

Add raw string and user defined literals to c++11 tests

cSpell.json
... ... @@ -474,6 +474,7 @@
474 474 "xpdf",
475 475 "xpost",
476 476 "xsltproc",
  477 + "yabcy",
477 478 "yscale",
478 479 "yuiop",
479 480 "zabcdefghi",
... ...
libtests/cxx11.cc
1 1 #include <iostream>
2 2 #include <cassert>
3 3 #include <cstring>
  4 +#include <cstdlib>
4 5 #include <functional>
5 6 #include <type_traits>
6 7 #include <cstdint>
... ... @@ -361,6 +362,29 @@ void do_regex()
361 362 assert((*m3)[2].matched);
362 363 }
363 364  
  365 +static long operator ""_x(char const* v)
  366 +{
  367 + return strtol(v, nullptr, 16);
  368 +}
  369 +
  370 +static std::string operator ""_y(char const* v, size_t len)
  371 +{
  372 + return "y" + std::string(v, len) + "y";
  373 +}
  374 +
  375 +void do_user_defined_literals()
  376 +{
  377 + assert(10_x == 16); // operator""_x("10")
  378 + assert("abc"_y == "yabcy"); // operator""_y("abc", 3)
  379 + // Raw literals. Optional matching label before and after ()
  380 + // allows embedding something that looks like the default end
  381 + // delimiter in the string.
  382 + assert(R"(abc)"_y == "yabcy");
  383 +
  384 + // This construct does not work in MSVC as of version 2019.
  385 + // assert(R"x(a)"bc)x"_y == "ya)\"bcy");
  386 +}
  387 +
364 388 int main()
365 389 {
366 390 do_functional();
... ... @@ -370,6 +394,7 @@ int main()
370 394 do_default_deleted();
371 395 do_smart_pointers();
372 396 do_regex();
  397 + do_user_defined_literals();
373 398 std::cout << "assertions passed\n";
374 399 return 0;
375 400 }
... ...