为什么 std::vector::iterator 不是连续的迭代器?
Why is std::vector::iterator not contiguous iterator?
根据std::vector
的cppref page:
iterator
LegacyRandomAccessIterator
也来自另一个cppref page:
The following standard library types are LegacyContiguousIterators:
vector::iterator
for value_type other than bool.
哪个是正确的?
std::vector<T>::iterator
(对于 T
而不是 bool
)是一个连续的迭代器。
A vector
meets all of the requirements of a container and [...] for an element type other than bool
, of a contiguous container.
[container.requirements.general]/13(强调我的):
A contiguous container is a container whose member types iterator and const_iterator meet the Cpp17RandomAccessIterator requirements ([random.access.iterators]) and model contiguous_iterator ([iterator.concept.contiguous]).
According to the cppref page of std::vector
:
iterator
LegacyRandomAccessIterator
这并不意味着迭代器不是连续的迭代器。它甚至没有谈论连续迭代器。
同一页还提到:
std::vector
(for T
other than bool
) meets the requirements of [...] ContiguousContainer [...].
并且 the page of ContiguousContainer 说:
The type X
satisfies ContiguousContainer if
- [...]
- The member types
X::iterator
and X::const_iterator
are LegacyContiguousIterators
两者都是正确的。所有向量迭代器都是随机访问迭代器。除了 vector of bool 之外的所有向量迭代器都是连续迭代器。请注意,所有连续迭代器也是随机访问迭代器。
前一个声明根本没有提供那么多信息,并且自从 c++17 引入了满足连续迭代器要求的名称的变化以来可能还没有更新。
根据std::vector
的cppref page:
iterator
LegacyRandomAccessIterator
也来自另一个cppref page:
The following standard library types are LegacyContiguousIterators:
vector::iterator
for value_type other than bool.
哪个是正确的?
std::vector<T>::iterator
(对于 T
而不是 bool
)是一个连续的迭代器。
A
vector
meets all of the requirements of a container and [...] for an element type other thanbool
, of a contiguous container.
[container.requirements.general]/13(强调我的):
A contiguous container is a container whose member types iterator and const_iterator meet the Cpp17RandomAccessIterator requirements ([random.access.iterators]) and model contiguous_iterator ([iterator.concept.contiguous]).
According to the cppref page of
std::vector
:
iterator
LegacyRandomAccessIterator
这并不意味着迭代器不是连续的迭代器。它甚至没有谈论连续迭代器。
同一页还提到:
std::vector
(forT
other thanbool
) meets the requirements of [...] ContiguousContainer [...].
并且 the page of ContiguousContainer 说:
The type
X
satisfies ContiguousContainer if
- [...]
- The member types
X::iterator
andX::const_iterator
are LegacyContiguousIterators
两者都是正确的。所有向量迭代器都是随机访问迭代器。除了 vector of bool 之外的所有向量迭代器都是连续迭代器。请注意,所有连续迭代器也是随机访问迭代器。
前一个声明根本没有提供那么多信息,并且自从 c++17 引入了满足连续迭代器要求的名称的变化以来可能还没有更新。