I am wondering whether
std::is_unsigned<bool>::value
is well defined according to the standard or not?
I ask the question because typename std::make_unsigned<bool>::type
is not well defined.
The Boolean type is unsigned and has the lowest ranking in its category of standard unsigned integer types; it may not be further qualified by the specifiers signed , unsigned , short , or long .
The unsigned keyword is a data type specifier, that makes a variable only represent non-negative integer numbers (positive numbers and zero). It can be applied only to the char , short , int and long types.
wchar_t is unsigned. Corresponding assembly code says movzwl _BOM, %eax .
unsigned long long is a 'simple-type-specifier' for the type unsigned long long int (so they're synonyms). The long long set of types is also in C99 and was a common extension to C++ compilers even before being standardized.
There is no concept of signedness for bool
. From [basic.fundamental]/6:
Values of type
bool
are eithertrue
offalse
. [Note: There are nosigned
,unsigned
,short
, orlong
bool
types or values. — end note] Values of typebool
participate in integral promotions (4.5).
By contrast, signedness is explicitly called out for the signed integer types (paragraph 2) and unsigned integer types (paragraph 3).
Now for the is_signed
and is_unsigned
traits. First off, the traits are always well-defined, but only interesting for arithmetic types. bool
is an arithmetic type, and is_signed<T>::value
is defined (see Table 49) as T(-1) < T(0)
. By using the rules of boolean conversion and standard arithmetic conversions, we see that this is is false
for T = bool
(because bool(-1)
is true
, which converts to 1
). Similarly, is_unsigned<T>::value
is defined as T(0) < T(-1)
, which is true
for T = bool
.
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