既然我们已经有了 true 和 false 作为 C++ 中的bool
类型,为什么还需要 std::boolean 以及它有什么用?
std::boolean
used to be a part of the draft standard (eg it can be found in n4835.pdf), but in the current draft it is replaced by an exposition-only concept boolean-testable
. The change happened around February.
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 qualifies.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.