|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Specifies that an expression of such a type and value category is convertible tobool, and for which the logical operators for the type or two differentBooleanTestable types have the usual behavior (includingshort-circuiting).
Contents |
Lete be an expression of a certain type and value category. The type and value category meet theBooleanTestable requirements if:
The standard does not define a named requirement with this name. It was originally proposed in an early resolution ofLWG2114, but was superseded by the exposition-only conceptboolean-testable in the final resolutionP2167R3. Because implementations generally expect the provided types to modelboolean-testable even in pre-C++20 modes, we intentedly treat P2167R3 as a defect report and transform theboolean-testable to legacy named requirements.
When the&& and|| operators are used with operands whose type and value category areBooleanTestable, built-in versions are selected and short-circuit evaluation is performed.
The type and value category of an expressione meet theBooleanTestable requirements if and only ifdecltype((e)) models | (since C++20) |
Examples ofBooleanTestable types (with any value category) includebool,std::true_type(since C++11),std::bitset<N>::reference, andint*.
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2114 (P2167R3) | C++98 | convertibility tobool was too weak to reflect the expectation of implementations | requirements strengthened |
(C++20) | specifies that a type can be used in Boolean contexts (exposition-only concept*)[edit] |