std::boolean
Defined in header <concepts>
|
||
template<class B> concept boolean = |
(since C++20) | |
The concept boolean<B>
specifies the requirements for a type usable in Boolean contexts. For boolean
to be satisfied, the logical operators must have the usual behavior (including short-circuiting). More precisely, given
-
b1
,b2
, two lvalues of type const std::remove_reference_t<B>,
boolean<B>
is satisfied only if:
- bool(b1) == !bool(!b1)
- b1 && b2, b1 && bool(b2) and bool(b1) && b2 are all equal to bool(b1) && bool(b2) and have the same short-circuit evaluation;
- b1 || b2, b1 || bool(b2) and bool(b1) || b2 are all equal to bool(b1) || bool(b2) and have the same short-circuit evaluation;
- bool(b1 == b2), bool(b1 == bool(b2)), and bool(bool(b1) == b2) are all equal to (bool(b1) == bool(b2));
- bool(b1 != b2), bool(b1 != bool(b2)), and bool(bool(b1) != b2) are all equal to (bool(b1) != bool(b2)).
Equality preservation
Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise).
Implicit expression variations
A requires expression that uses an expression that is non-modifying for some constant lvalue operand also requires implicit expression variations.
Notes
Examples of boolean
types include bool, std::true_type, and std::bitset<N>::reference. Pointers are not boolean
types.