34

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:

enter image description here

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.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
  • 2
    [`bool` and `char` are integral types](http://ideone.com/cbP0G7). – Bill Lynch Nov 20 '14 at 06:17
  • Maybe you should ask Walter E. Brown? Whatever he's talking about, it's not something specifically spelled out in the C++ language spec. – Adam Rosenfield Nov 20 '14 at 07:06
  • function ? aggregate ? pod ? xvalue ? glvalue ? literal ? constexpr ? .... – v.oddou Nov 20 '14 at 07:43
  • 4
    Fwiw, here's my chart on this subject:http://howardhinnant.github.io/TypeHiearchy.pdf – Howard Hinnant Nov 20 '14 at 15:48
  • @HowardHinnant: very nice :) I'm saving it ! However I see it dates back 2007, would you care to add the Stroustrup's W classification for possible types of expressions ? (glvalue, rvalue, lvalue, xvalue). also `constexpr` doesn't appear. Maybe partitionning integrals in 2 bubbles (signed/unsigned/char) witin the big one ? Also in any case, is it possible to CV-qualify any of those types ? – v.oddou Nov 21 '14 at 03:24
  • @v.oddou: I'm going to stand pat. This chart models the primary type categories ([meta.unary.cat]) and composite type traits ([meta.unary.comp]) as still specified in C++14 (7 years later). And clearly shows the 14 primary type categories referred to by Walter. If and when we get new primary or composite categories, I'll update at that time. Not that the charts you are proposing aren't valuable, just that this is not the purpose of my chart. – Howard Hinnant Nov 21 '14 at 03:34
  • Oh, about cv-qualifications: The C++11 and C++14 standards explicitly state that for any given type `T`, the result of applying one of these templates to `T` and to *cv-qualified* `T` shall yield the same result. This is not explicitly shown in my chart. You just have to read the standard. – Howard Hinnant Nov 21 '14 at 03:42
  • Thanks. Also I verified and concur that there are indeed 14 leaves categories in your graph. – v.oddou Nov 21 '14 at 03:56

1 Answers1

30

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;
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271