本文介绍了混淆迭代器无效在deque的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对deque中的迭代器无效有点困惑。
(在的上下文中问题)

I'm bit confused regarding iterator invalidation in deque. (In the context of this question)

以下是摘录自The C ++ Standard Library:A Tutorial and Reference,
By Nicolai M. Josuttis

Following is the excerpts from -- The C++ Standard Library: A Tutorial and Reference, By Nicolai M. Josuttis

下面是网站:

IMHO,deque是第一个块在一个方向生长,最后一个块在相反方向生长。

IMHO, deque is collection of blocks with first block growing in one direction and the last block in opposite direction.

  -   -  -  
  -   -  -
  |   -  -  ^
  |   -  -  |
  V   -  -  |
      -  -  -
      -  -  -

push_back ,push_front 不应该对deque迭代器有任何影响(我同意Josuttis)。

push_back, push_front should not have any impact on deque iterators ( I agree with Josuttis).

正确的解释是什么?这个标准说了什么?

What is the correct explanation? what the standard say on this?

推荐答案

1效果:插入中间
的deque使所有
迭代器和对deque的元素
的引用无效。 deque的任一端
插入使所有
迭代器无效,但对引用
对deque的元素的有效性没有
的影响。


1 Effects: An insert in the middle of the deque invalidates all the iterators and references to elements of the deque. An insert at either end of the deque invalidates all the iterators to the deque, but has no effect on the validity of references to elements of the deque."

因此两者都是正确的。正如Josuttis所指出的,正面或背面的插入不会使对deque的元素的引用无效,

So both are correct. As Josuttis indicates, insertion at the front or back doesn't invalidate references to elements of the deque, only iterators to the deque itself.

编辑:A 基本上说同样的事情(第23.2.2.3节)

A more up-to-date draft says essentially the same thing (section 23.2.2.3)

这篇关于混淆迭代器无效在deque的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:16