c++11 - 什么样的迭代器支持随机访问但不支持 C++ 中的连续存储?

标签 c++11 iterator categories contiguous

我看到自 C++17 以来有一个新的迭代器,下面通过 cppreference 中的屏幕截图列出。我很困惑。什么样的迭代器是随机访问而不是C++中的连续存储??否则, ContiguousIterator 不比 RandomAccessIterator 强大?对吧?

enter image description here

然后是链接here

最佳答案

一个具有随机访问迭代器的非连续容器是 std::deque .引用 cppreference 站点:

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)

关于c++11 - 什么样的迭代器支持随机访问但不支持 C++ 中的连续存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40128250/

相关文章:

gcc中的C++ 11样式[[未使用]]属性?

c++ - 当可以使用RVO时,为什么要按shared_ptr而不是按值返回?

c++ - 使用引用推导模板包中的冲突类型

objective-c - XCode 4.5 警告父/子类类别之间的方法名称冲突

c++ - wxWidgets - 在没有事件异常的情况下终止调用(使用 std::thread)

c++迭代对象列表并删除对象

c++ - 使用 map::find 查找键并返回值

c++ - 使用列表迭代器获取所有值

php - 移动自定义帖子类型的 wordpress 帖子及其类别以及类别的子父关系

mysql - 每个类别的php-sql限制查询