Jakie jest 15 klasyfikacji typów w C++?

Podczas konferencjiCppCon2014 dyskusja Walter E. Brown stwierdza, że istnieje15 klasyfikacji typów w C++, które standard opisuje.

" 15 partycji uniwersum typów C++."
"void jest jednym z nich."Walter E. Brown.

Jakie są pozostałe 14?


Przekopując się przez standard, znalazłem następujące:

// 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, to więcej niż 15. W każdym razie są to cechy typu. Oni są używane do testowania pewnych właściwości typów w czasie kompilacji. Na przykład typ integer zwróci true dla is_integral, is_fundamental, i jest is_scalar. Być może 15 to niektóre z tych wymienionych powyżej, a reszta to podkategorie dla innych.

Oto moja próba stworzenia drzewa typów języka:

Tutaj wpisz opis obrazka

Moje przypuszczenie:

 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

Ale zauważ również, że bool, char, i enum są całkami, więc naprawdę nie jestem pewien tego lista.

Author: Trevor Hickey, 2014-11-20

1 answers

Rozmawiałem bezpośrednio z Walterem i to było po prostu nieporozumienie.

"niestety, wkrótce potem zdałem sobie sprawę, że pomyliłem się i dlatego popełnił błąd off-by-one podczas rozmowy: jest 14 (Nie 15) klasyfikacje typów. Zobacz listę kategorii Typ podstawowy predykaty w klauzuli [meta.unary.cat] w standardzie C++; te odpowiadają klasyfikacjom ustalonym dla języka podstawowego w [podstawowe.rodzaje]."--WEB

To powiedziawszy, oni są:

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;
 25
Author: Trevor Hickey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-20 07:52:15