作者:我爱宝宝们小童鞋_244_571_742 | 来源:互联网 | 2023-10-13 08:38
Iamwonderingwhether我想知道是否std::is_unsigned<bool>::valueiswelldefinedaccordingtot
I am wondering whether
我想知道是否
std::is_unsigned::value
is well defined according to the standard or not?
是否按照标准来定义?
I ask the question because typename std::make_unsigned::type
is not well defined.
我问这个问题是因为typename std::make_unsigned
:::type没有很好的定义。
4 个解决方案
9
Yes it is well defined and the result should be std::is_unsigned::value == true
是的,它的定义很好,结果应该是std::is_unsigned
::value == true。
The documentation for std::is_signed
says
std::is_signed说的文档
If T
is a signed arithmetic type, provides the member constant value equal true. For any other type, value is false.
如果T是一个有符号的算术类型,则提供成员常量值等于true。对于任何其他类型,值都是假的。
So then if you look at std::is_arithmetic
如果你看看std: is_算术
If T is an arithmetic type (that is, an integral type or a floating-point type), provides the member constant value equal true. For any other type, value is false.
如果T是一种算术类型(即整数类型或浮点类型),则提供成员常量值为true。对于任何其他类型,值都是假的。
Which finally leads to std::is_integral
这最终导致std::is_integral ?
Checks whether T is an integral type. Provides the member constant value which is equal to true, if T is the type bool
, char
, char16_t
, char32_t
, wchar_t
, short
, int
, long
, long long
, or any implementation-defined extended integer types, including any signed, unsigned, and cv-qualified variants. Otherwise, value is equal to false.
检查T是否为整数类型。如果T是类型bool、char、char16_t、char32_t、char32_t、wchar_t、short、int、long、long、long、long、long,或者任何实现定义的扩展整数类型,包括任何已签名的、未签名的和cv限定的变体,那么提供的成员常量值就等于true。否则,值等于false。
Interestingly, there is another function std::numeric_limits::is_signed
that states
有趣的是,还有一个std::numeric_limits::is_signed that states。
The value of std::numeric_limits::is_signed
is true
for all signed arithmetic types T
and false
for the unsigned types. This constant is meaningful for all specializations.
std:::numeric_limits
::is_signed为所有有符号算术类型T的真值,无符号类型为假值。这个常数对所有的专门化都有意义。
Where the specialization for bool
is listed as false
, which also confirms that bool
is considered unsigned.
其中bool的专门化被列出为false,这也确认了bool被认为是无符号的。