aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/cxx11.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-01 17:28:24 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:02 +0100
commit7d48b446b32b762074e0de6d8f22311a88c5c8ef (patch)
tree3860fcf9570826e128dae5064c2a5db91026b2b0 /libtests/cxx11.cc
parentc60b4ea55a7d0844a81417d004f32c1b5f9f9df0 (diff)
downloadqpdf-7d48b446b32b762074e0de6d8f22311a88c5c8ef.tar.zst
Add raw string and user defined literals to c++11 tests
Diffstat (limited to 'libtests/cxx11.cc')
-rw-r--r--libtests/cxx11.cc25
1 files changed, 25 insertions, 0 deletions
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;
}