"except that a default constructed array is not empty" 是什么意思?
What does "except that a default constructed array is not empty" mean?
在 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, Table 96 Container Requirements中,显示了默认构造对象X u;
,其中post条件为u.empty()
。据推测,以下内容:
std::array<int, 0> a;
应该导致 a.empty()
输出 1
,确实如此。那么这里的 "empty" 是什么意思?
您正在查看边界大小写 - 大小为零的数组是否为空?忽略那个具体问题,标准引用说一般 std::array<T,N> arr
在默认构造中不满足 post 条件 arr.empty()
。事实上,一个 std::array<T, N>
只有在 N==0
时才是 empty()
。这个定义也是自然的——std::array<T,N>::size()
是一个 constexpr
,值为 N
,empty()
应该是 size() == 0
.
的同义词
在 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, Table 96 Container Requirements中,显示了默认构造对象X u;
,其中post条件为u.empty()
。据推测,以下内容:
std::array<int, 0> a;
应该导致 a.empty()
输出 1
,确实如此。那么这里的 "empty" 是什么意思?
您正在查看边界大小写 - 大小为零的数组是否为空?忽略那个具体问题,标准引用说一般 std::array<T,N> arr
在默认构造中不满足 post 条件 arr.empty()
。事实上,一个 std::array<T, N>
只有在 N==0
时才是 empty()
。这个定义也是自然的——std::array<T,N>::size()
是一个 constexpr
,值为 N
,empty()
应该是 size() == 0
.