注册 登录
编程论坛 C++教室

c++primer 上一句话不懂。。

slash5999 发布于 2013-05-22 19:48, 572 次点击
为什么说:对于deque容器,如果删除时不包含第一个元素或最后一个元素,那么该deque容器相关的的所有迭代器都会失效。。。

这是为什么呢?
2 回复
#2
peach54602013-05-22 21:33
deque是两端开口的容器,中间是不能操作的
去看看deque的实现
#3
rjsp2013-05-23 08:40
不知道他这句话是C++标准如此,还是仅仅只是他自己写的VC STL库如此?我猜应该是后者。

不放心,还是去查一下吧,ISO/IEC 14882:2003(E) 第 480 页,关于 deque::erase 就只有如下这么多:
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
4 Effects: An erase in the middle of the deque invalidates all the iterators and references to elements of the deque. An erase at either end of the deque invalidates only the iterators and the references to the erased elements.
5 Complexity: The number of calls to the destructor is the same as the number of elements erased, but the number of the calls to the assignment operator is at most equal to the minimum of the number of elements before the erased elements and the number of elements after the erased elements.
6 Throws: Nothing unless an exception is thrown by the copy constructor or assignment operator of T.
1