为什么 T[] 可以简单复制但不能简单破坏?
Why is T[] trivially copyable but not trivially destructible?
首先,T[]
的正确术语是什么(不是 T[12]
也不是 T*
)?
其次,如果 T
既可平凡复制又可平凡破坏,为什么 T[]
平凡可复制但不可平凡破坏?我知道它用于有界数组 (T[12]
).
First of all, what is the correct term for T[]
它是一个未知边界的数组(下面简称为AOUB)。
Why is T[] not trivially destructible?
标准(最新草案):
[meta.unary.prop]
Trait: is_trivially_destructible
Condition: is_destructible_v is true and ...
Trait: is_destructible
Condition: Either T is a reference type, or T is a complete object type for which ...
AOUB 既不是引用类型,也不是完整类型。因此它没有 is_destructible
特征,因此它也没有 is_trivially_destructible
。
Why is T[] trivially copyable
标准(最新草案):
[meta.unary.prop]
Trait: is_trivially_copyable
Condition: T is a trivially copyable type ([basic.types])
[basic.types.general]
Arithmetic types ..., arrays of such types, and ... are collectively called trivially copyable types.
请注意,未知边界数组也不例外。根据这条规则,它们也可以简单地复制。
首先,T[]
的正确术语是什么(不是 T[12]
也不是 T*
)?
其次,如果 T
既可平凡复制又可平凡破坏,为什么 T[]
平凡可复制但不可平凡破坏?我知道它用于有界数组 (T[12]
).
First of all, what is the correct term for T[]
它是一个未知边界的数组(下面简称为AOUB)。
Why is T[] not trivially destructible?
标准(最新草案):
[meta.unary.prop]
Trait: is_trivially_destructible
Condition: is_destructible_v is true and ...
Trait: is_destructible
Condition: Either T is a reference type, or T is a complete object type for which ...
AOUB 既不是引用类型,也不是完整类型。因此它没有 is_destructible
特征,因此它也没有 is_trivially_destructible
。
Why is T[] trivially copyable
标准(最新草案):
[meta.unary.prop]
Trait: is_trivially_copyable
Condition: T is a trivially copyable type ([basic.types])
[basic.types.general]
Arithmetic types ..., arrays of such types, and ... are collectively called trivially copyable types.
请注意,未知边界数组也不例外。根据这条规则,它们也可以简单地复制。