As discussed at Why is nullptr_t not a keyword, it is better to avoid introducing new keywords because they can break backward compatibility.
Why then are char16_t and char32_t keywords, when they could just as well have been defined like so?
namespace std { typedef decltype(u'q') char16_t; typedef decltype(U'q') char32_t; }
The proposal itself explains why: to allow overloading with the underlying types of uint_least16_t and uint_least32_t. If they were typedefed this wouldn't be possible.
Define
char16_tto be a distinct new type, that has the same size and representation asuint_least16_t. Likewise, definechar32_tto be a distinct new type, that has the same size and representation asuint_least32_t.[N1040 defined
char16_tandchar32_tas typedefs touint_least16_tanduint_least32_t, which make overloading on these characters impossible.]
As for why they aren't in the std namespace, this is for compatibility with the original C proposal. C++ prohibits the C definitions from appearing in its own version of <cuchar>
[c.strings] / 3
The headers shall not define the types
char16_t,char32_t, andwchar_t(2.11).
The types then would need to be global typedefs, which carries its own set of issues such as
typedef decltype(u'q') char16_t; namespace foo { typedef int char16_t; } The reason for std::nullptr_t not being a keyword can be found in the question you linked
We do not expect to see much direct use of
nullptr_tin real programs.
making nullptr_t the real exception here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With