在由Walter E. Brown发表的
CppCon2014 conference talk期间,他指出标准描述的C中有15种类型的类型。
“C类型宇宙的15个分区”。
“void是其中之一。 – Walter E. Brown。
什么是其他14?
在探索标准时,我发现了以下内容:
// 20.11.4.1
primary type categories:
template struct is_void;
template struct is_integral;
template struct is_floating_point;
template struct is_array;
template struct is_pointer;
template struct is_lvalue_reference;
template struct is_rvalue_reference;
template struct is_member_object_pointer;
template struct is_member_function_pointer;
template struct is_enum;
template struct is_union;
template struct is_class;
template struct is_function;
// 20.11.4.2
composite type categories:
template struct is_reference;
template struct is_arithmetic;
template struct is_fundamental;
template struct is_object;
template struct is_scalar;
template struct is_compound;
template struct is_member_pointer;
嗯,这是超过15.这些都是类型特征无论如何。它们用于在编译时测试类型的某些属性。例如,整数类型将返回is_integral,is_fundamental的值,为is_scalar。也许15是上面列出的一些,其余的是其他人的子类别。
这里是我试图做一个语言的类型树的尝试:
我猜:
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
但还要注意,bool,char和enum都是整数类型,所以我对这个列表真的不太有信心。