MythTV master
sizetliteral.h
Go to the documentation of this file.
1#ifndef SIZETLITERAL_H
2#define SIZETLITERAL_H
3
4#ifdef __cpp_size_t_suffix
5# warning "This code should be converted to use the c++23 Z/UZ literals."
6#endif
7
8// From https://en.cppreference.com:
9//
10// Literal suffixes for size_t and its signed version
11//
12// 1) z or Z => the signed version of std::size_t (since C++23)
13//
14// 2) both z/Z and u/U => std::size_t (since C++23)
15
16// Analysis:
17//
18// GCC >= 11.1 and Clang >= 13.0 (*) have builtin support for the 'Z'
19// and 'UZ' literals, but they don't set __cpp_size_t_suffix unless
20// you compile with -std=c++23. They also issue a warning about each
21// usage of Z/UZ, and its impossible to disable those warnings. This
22// means its impossible to use the built-in compiler support for the
23// Z/UZ literal when compiling c++17 code. Its also impossible to
24// create our own user-defined Z/UZ literals without the compiler also
25// complaining. Sigh. This means there's no way to implement the Z/UZ
26// literals now so that the code will compile under c++17 and c++23
27// without change.
28//
29// * 13.1.6 for Apple Clang.
30//
31// The fallback is to create _Z/_UZ literals that can be used in c++17, and
32// at some point in the future when the code is uplifted to compile with
33// -std=c++23 these should be converted to use the compiler supplied Z/UZ.
34
35constexpr ssize_t operator ""_Z(unsigned long long v)
36 { return static_cast<ssize_t>(v); }
37constexpr size_t operator ""_UZ(unsigned long long v)
38 { return static_cast<size_t>(v); }
39
40#endif // SIZETLITERAL_H