gpt4 book ai didi

c++ - "except that a default constructed array is not empty"是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:03 25 4
gpt4 key购买 nike

在 N3337 中,我正在阅读 §23.3.2.1/3,它指出:

An array satisfies all of the requirements of a container and of a reversible container (23.2), except that a default constructed array object is not empty and that swap does not have constant complexity.

在 §23.2.1,表 96 容器要求中,它显示了一个默认构造的对象 X u;,其中后置条件是 u.empty()。据推测,以下内容:

std::array<int, 0> a;

应该导致 a.empty() 输出 1,它确实如此。那么这里的“空”是什么意思呢?

最佳答案

您正在查看边界情况 - 大小为零的数组是否为空?忽略那个具体问题,标准引述说一般 std::array<T,N> arr , 在默认构造中,不满足后置条件 arr.empty() .事实上,一个std::array<T, N>empty()仅当 N==0 .这个定义也很自然 - std::array<T,N>::size()constexpr具有值(value) Nempty()应与 size() == 0 同义.

关于c++ - "except that a default constructed array is not empty"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229382/

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