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 converted false; other value converted true. [...]

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 bool can converted prvalue of type int, false becoming 0 , true becoming 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>::value true, same result integral_constant<bool, t(-1) < t(0)>::value; otherwise, false

which has same result in case of t == bool.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -