C++11 first introduced support for defining new literals into C++ by means of user-defined literals. Does C++11 or later also predefine suffixes for fixed-width integer literals for types in <cstdint>
?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
No. As of C++14 the only literal suffixes defined by the standard are provided by
<chrono>
,<complex>
and<string>
headers in the standard library. The<chrono>
header defines theh
,min
,s
,ms
,us
,ns
suffixes for time durations,<complex>
defines thei
,il
andif
suffixes for imaginary numbers, and<string>
defines thes
suffix forbasic_string
literals.However, one can easily define their own fixed-width literals like this:
Warning: The above code will silently give the wrong result if used on literals which don't fit into
unsigned long long
, as well as overflow if the literal value, doesn't fit into the requested type, e.g.999_int8
. A better implementation (GPL-3 licensed) would probably have to parse the literal character-by-character andstatic_assert
on overflow, like this.The downside of using user defined literals is that one needs to prefix the suffixes with an underscore
_
, because suffixes without the underscore are reserved for future standardization according to §17.6.4.3.4.