为什么 std::is_aggregate<T> 是一个集合?
Why is std::is_aggregate<T> an aggregate?
我一直认为 std::is_same
、std::is_void
或 std::is_aggregate
等类型应该继承自 std::integral_constant
,或者更具体地说,继承自 [=16] =].
但是,聚合 classes 不能有基数 class by definition,但是当我在 std::is_aggregate_v<T>
中使用这些类型作为 T
时,我得到 true
。很明显,它们 不是 来自 std::bool_constant
?
所以我的问题是:
为什么 std::is_aggregate_v<std::is_aggregate<void>>
是真的,至少对于 GCC 和 Clang 是这样?标准不是规定std::is_aggregate
是从std::bool_constant
派生的吗?如果不是,这是否意味着它将上述行的值保留为实现细节?
However, aggregate classes must not have a base class by definition
这不再是事实。 [dcl.init.aggr]/1 定义聚合为
An aggregate is an array or a class with
no user-provided, explicit, or inherited constructors ([class.ctor]),
no private or protected non-static data members (Clause [class.access]),
no virtual functions, and
no virtual, private, or protected base classes ([class.mi]).
[ Note: Aggregate initialization does not allow accessing protected and private base class' members or constructors. — end note ]
不再有像在 C++14 和更早版本中那样没有基数 class 的条件。只要它有一个 public,现在允许的非虚拟基础 class。这意味着类型特征现在被认为是聚合,只要以上对它们适用
自 C++17 起,类 具有非虚拟、非私有或受保护的基数是聚合:https://en.cppreference.com/w/cpp/language/aggregate_initialization
我一直认为 std::is_same
、std::is_void
或 std::is_aggregate
等类型应该继承自 std::integral_constant
,或者更具体地说,继承自 [=16] =].
但是,聚合 classes 不能有基数 class by definition,但是当我在 std::is_aggregate_v<T>
中使用这些类型作为 T
时,我得到 true
。很明显,它们 不是 来自 std::bool_constant
?
所以我的问题是:
为什么 std::is_aggregate_v<std::is_aggregate<void>>
是真的,至少对于 GCC 和 Clang 是这样?标准不是规定std::is_aggregate
是从std::bool_constant
派生的吗?如果不是,这是否意味着它将上述行的值保留为实现细节?
However, aggregate classes must not have a base class by definition
这不再是事实。 [dcl.init.aggr]/1 定义聚合为
An aggregate is an array or a class with
no user-provided, explicit, or inherited constructors ([class.ctor]),
no private or protected non-static data members (Clause [class.access]),
no virtual functions, and
no virtual, private, or protected base classes ([class.mi]).
[ Note: Aggregate initialization does not allow accessing protected and private base class' members or constructors. — end note ]
不再有像在 C++14 和更早版本中那样没有基数 class 的条件。只要它有一个 public,现在允许的非虚拟基础 class。这意味着类型特征现在被认为是聚合,只要以上对它们适用
自 C++17 起,类 具有非虚拟、非私有或受保护的基数是聚合:https://en.cppreference.com/w/cpp/language/aggregate_initialization