gpt4 book ai didi

c++ - 为什么 T[] 可以简单复制但不能简单破坏?

转载 作者:行者123 更新时间:2023-12-03 06:54:26 25 4
gpt4 key购买 nike

首先,T[] 的正确术语是什么(不是 T[12] 也不是 T*)?

其次,如果 T 既可平凡复制又可平凡破坏,为什么 T[] 平凡可复制但不可平凡破坏?我知道它用于有界数组 (T[12])。

godbolt

最佳答案

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.

请注意,未知边界数组也不异常(exception)。根据这条规则,它们也可以简单地复制。

关于c++ - 为什么 T[] 可以简单复制但不能简单破坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64459610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com