c++ - Is std::is_signed<bool>::value guaranteed to return false? -
i know std::numeric_limits<bool>::is_signed false true std::is_signed<bool>::value? thanks
std::is_signed defined follows (table 49 - type property predicates, n3485):
is_arithmetic<t>::value && t(-1) < t(0) bool integral type [basic.fundamental]/7, therefore arithmetic type [basic.fundamental]/8.
bool(x) x int, uses boolean conversion [conv.bool]/1
a prvalue of arithmetic, unscoped enumeration, pointer, or pointer member type can converted prvalue of type
bool. 0 value, null pointer value, or null member pointer value convertedfalse; other value convertedtrue. [...]
so have bool(-1) < bool(0) evaluating true < false, subject (see [expr.rel]/2) usual arithmetic conversions [expr]/10 => integral promotion [conv.prom]/6
a prvalue of type
boolcan converted prvalue of typeint,falsebecoming 0 ,truebecoming one.
the comparison reads 1 < 0, false. the check guaranteed evaluate false.
in n3797, after fixing lwg 2197, check defined follows:
if
is_arithmetic<t>::valuetrue, same resultintegral_constant<bool, t(-1) < t(0)>::value; otherwise,false
which has same result in case of t == bool.
Comments
Post a Comment