3

I saw that there is a new iterator since C++17,below listed by a screenshot in cppreference. I was a lot confused. What kind of iterators is random access but not contiguous storage in C++?? otherwise, the ContiguousIterator is not powerful than RandomAccessIterator ? right?

enter image description here

And then the link here

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
Andy Cong
  • 109
  • 1
  • 10

1 Answers1

4

One non-contiguous container with random-access iterators is std::deque. Quoting the cppreference site:

As opposed to std::vector, the elements of a deque are not stored contiguously: typical implementations use a sequence of individually allocated fixed-size arrays.

The complexity (efficiency) of common operations on deques is as follows:

  • Random access - constant O(1)
  • Insertion or removal of elements at the end or beginning - constant O(1)
  • Insertion or removal of elements - linear O(n)
Community
  • 1
  • 1
Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455