17 Concepts library [concepts]

17.5 Comparison concepts [concepts.compare]

17.5.2 Concept Boolean [concept.boolean]

The Boolean concept specifies the requirements on a type that is usable in Boolean contexts.
template<class B> concept Boolean = Movable<remove_cvref_t<B>> && // (see [concepts.object]) requires(const remove_reference_t<B>& b1, const remove_reference_t<B>& b2, const bool a) { requires ConvertibleTo<const remove_reference_t<B>&, bool>; !b1; requires ConvertibleTo<decltype(!b1), bool>; b1 && a; requires Same<decltype(b1 && a), bool>; b1 || a; requires Same<decltype(b1 || a), bool>; b1 && b2; requires Same<decltype(b1 && b2), bool>; a && b2; requires Same<decltype( a && b2), bool>; b1 || b2; requires Same<decltype(b1 || b2), bool>; a || b2; requires Same<decltype( a || b2), bool>; b1 == b2; requires ConvertibleTo<decltype(b1 == b2), bool>; b1 == a; requires ConvertibleTo<decltype(b1 == a), bool>; a == b2; requires ConvertibleTo<decltype( a == b2), bool>; b1 != b2; requires ConvertibleTo<decltype(b1 != b2), bool>; b1 != a; requires ConvertibleTo<decltype(b1 != a), bool>; a != b2; requires ConvertibleTo<decltype( a != b2), bool>; };
Let b1 and b2 be lvalues of type const 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)).
[Example
:
The types bool, true_­type ([meta.type.synop]), and bitset<N>::reference ([template.bitset]) are Boolean types.
Pointers, smart pointers, and types with only explicit conversions to bool are not Boolean types.
end example
]