gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 04:12:39 25 4
gpt4 key购买 nike

我看到自 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com