Rectangle 27 1

c++ Is std::is_unsignedbool::value well defined?


A UnaryTypeTrait describes a property of a type. It shall be a class template that takes one template type argument and, optionally, additional arguments that help define the property being described. It shall be DefaultConstructible, CopyConstructible, and publicly and unambiguously derived, directly or indirectly, from its BaseCharacteristic, which is a specialization of the template integral_constant (20.10.3), with the arguments to the template integral_constant determined by the requirements for the particular property being described. The member names of the BaseCharacteristic shall not be hidden and shall be unambiguously available in the UnaryTypeTrait.

Each of these templates shall be a UnaryTypeTrait (20.10.1) with a BaseCharacteristic of true_type if the corresponding condition is true, otherwise false_type.

From this it follows that the construct std::is_unsigned<T>::value has to be well-defined for any type T, whether the concept of "signedness" makes sense for the type or not.

Yes, it is well-defined, as is any other unary type trait.

Note
Rectangle 27 1

c++ Is std::is_unsignedbool::value well defined?


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.

There is no concept of signedness for bool. From [basic.fundamental]/6:

Values of type bool are either true of false. [Note: There are no signed, unsigned, short, or long bool types or values. end note] Values of type bool participate in integral promotions (4.5).

Note