在 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 constructedarray
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) N
和 empty()
应与 size() == 0
同义.
关于c++ - "except that a default constructed array is not empty"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229382/