Since we already have true and false as the type bool
in C , why do we need std::boolean and what's the use of it?
CodePudding user response:
std::boolean
used to be a part of the C 20 draft standard (e.g. it can be found in N4835), but in the actual C 20 standard it is replaced by an exposition-only concept boolean-testable
. The change happened around February 2020 as a result of adoption of P1964R2 .
In either incarnation it is a concept, not a type. That is, a template that says whether its argument type can be used as a boolean. bool
obviously can be used this way, but not only: integral types, pointer types, and any class that defines a conversion to bool
and/or overloads boolean operators like !
and &&
also qualify.