0 < 0
0 < 1
1 < 0
1 < 1
false < false
false < true
true < false
true < true
Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
@chris I am not super familiar with that section so I would have to think about it but I don't think the answer changes from what I can see.
A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true
Going back to section 5.9 to see the mechanics of the relational operators further, it says:
Integral and floating types are collectively called arithmetic
Nice, that's about as explicit as any answer could possibly be, while still easy to read. A nit: I think you bolded the wrong "type": "The operands shall have arithmetic, enumeration, or pointer type, or type std::nullptr_t." Adding parentheses for clarity gives ((arithmetic, enumeration, or pointer) type) or (type std::nullptr_t).
Otherwise, the integral promotions (4.5) shall be performed on both operands
The operands shall have arithmetic, enumeration, or pointer type, or type std::nullptr_t. The operators
< (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) all yield
false or true. The type of the result is bool
The operations are well defined according to the draft C++ standard.
The usual arithmetic conversions are performed on operands of arithmetic or enumeration type.
Types bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectively
called integral types.
Yeah, the promotion is the first thing to happen either way.
and bools are arithematic types from 3.9.1 Fundamental types
and true and false are boolean literals from 2.14.6 Boolean literals: