diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-01-01 17:28:24 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-01-30 19:11:02 +0100 |
commit | 7d48b446b32b762074e0de6d8f22311a88c5c8ef (patch) | |
tree | 3860fcf9570826e128dae5064c2a5db91026b2b0 | |
parent | c60b4ea55a7d0844a81417d004f32c1b5f9f9df0 (diff) | |
download | qpdf-7d48b446b32b762074e0de6d8f22311a88c5c8ef.tar.zst |
Add raw string and user defined literals to c++11 tests
-rw-r--r-- | cSpell.json | 1 | ||||
-rw-r--r-- | libtests/cxx11.cc | 25 |
2 files changed, 26 insertions, 0 deletions
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 <iostream> #include <cassert> #include <cstring> +#include <cstdlib> #include <functional> #include <type_traits> #include <cstdint> @@ -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; } |