From 7d48b446b32b762074e0de6d8f22311a88c5c8ef Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 1 Jan 2022 11:28:24 -0500 Subject: [PATCH] Add raw string and user defined literals to c++11 tests --- cSpell.json | 1 + libtests/cxx11.cc | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cSpell.json b/cSpell.json index 09d00693..888167b8 100644 --- a/cSpell.json +++ b/cSpell.json @@ -474,6 +474,7 @@ "xpdf", "xpost", "xsltproc", + "yabcy", "yscale", "yuiop", "zabcdefghi", diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc index bec86cec..20a5134f 100644 --- a/libtests/cxx11.cc +++ b/libtests/cxx11.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -361,6 +362,29 @@ void do_regex() assert((*m3)[2].matched); } +static long operator ""_x(char const* v) +{ + return strtol(v, nullptr, 16); +} + +static std::string operator ""_y(char const* v, size_t len) +{ + return "y" + std::string(v, len) + "y"; +} + +void do_user_defined_literals() +{ + assert(10_x == 16); // operator""_x("10") + assert("abc"_y == "yabcy"); // operator""_y("abc", 3) + // Raw literals. Optional matching label before and after () + // allows embedding something that looks like the default end + // delimiter in the string. + assert(R"(abc)"_y == "yabcy"); + + // This construct does not work in MSVC as of version 2019. + // assert(R"x(a)"bc)x"_y == "ya)\"bcy"); +} + int main() { do_functional(); @@ -370,6 +394,7 @@ int main() do_default_deleted(); do_smart_pointers(); do_regex(); + do_user_defined_literals(); std::cout << "assertions passed\n"; return 0; }