随机访问迭代器和双端队列

Random access iterators and deque

我今天读了一些文章,它说由于 std::deque 确实有一个随机访问迭代器,它的项目检索率时间复杂度是 O(1)。虽然我同意项目检索的时间复杂度为 O(1) 的事实,但是随机访问迭代器与它有什么关系?

RandomAccessIterator概念要求+-操作必须在常数时间内实现:

来自[iterator.concept.random.access]

The RandomAccessIterator concept adds support for constant-time advancement with +=, +, -=, and -, as well as the computation of distance in constant time with -. Random access iterators also support array notation via subscripting.

这意味着任何实现 random-access 迭代器的 standard-compliant 容器必须提供 constant-time 元素检索。