During a CppCon2014 conference talk by Walter E. Brown, he states that there are 15 classifications of types in C++ that the standard describes.
"15 partitions of the universe of C++ types."
"void is one of them." -- Walter E. Brown.
What are the other 14?
While digging through the standard, I found the following:
// 20.11.4.1 primary type categories: template <class T> struct is_void; template <class T> struct is_integral; template <class T> struct is_floating_point; template <class T> struct is_array; template <class T> struct is_pointer; template <class T> struct is_lvalue_reference; template <class T> struct is_rvalue_reference; template <class T> struct is_member_object_pointer; template <class T> struct is_member_function_pointer; template <class T> struct is_enum; template <class T> struct is_union; template <class T> struct is_class; template <class T> struct is_function; // 20.11.4.2 composite type categories: template <class T> struct is_reference; template <class T> struct is_arithmetic; template <class T> struct is_fundamental; template <class T> struct is_object; template <class T> struct is_scalar; template <class T> struct is_compound; template <class T> struct is_member_pointer;
Hmm, that's more than 15. These are type traits anyhow. They are used to test certain properties of types at compile time. For example, an integer
type would give back true for is_integral
, is_fundamental
, and is is_scalar
. Perhaps the 15 are some of the ones listed above and the rest are sub categories to others.
Here's my attempt of trying to make a type tree of the language:
My guess:
1. void 2. bool 3. char 4. nullptr 5. integral (signed) 6. integral (unsigned) 7. floating 8. enum 9. array 10. class 11. union 12. lvalue reference 13. rvalue reference 14. member object pointer 15. member function pointer
But also note that bool
, char
, and enum
are all integral types, so I'm really not very confident in this list.
I spoke with Walter directly, and it was simply a miscount.
"Alas, I realized shortly thereafter that I'd miscounted and hence committed an off-by-one error during the talk: there are 14 (not 15) type classifications. See the list of primary type category predicates in clause [meta.unary.cat] in the C++ standard; these correspond to the classifications established for the core language in [basic.types]." --WEB
That being said, they are:
template <class T> struct is_void; template <class T> struct is_null_pointer; //<- arrived in C++11 (std::nullptr_t) template <class T> struct is_integral; template <class T> struct is_floating_point; template <class T> struct is_array; template <class T> struct is_pointer; template <class T> struct is_lvalue_reference; template <class T> struct is_rvalue_reference; template <class T> struct is_member_object_pointer; template <class T> struct is_member_function_pointer; template <class T> struct is_enum; template <class T> struct is_union; template <class T> struct is_class; template <class T> struct is_function;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With