| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 556 人关注过本帖
标题:c++primer 上一句话不懂。。
只看楼主 加入收藏
slash5999
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-11-28
结帖率:60%
收藏
 问题点数:0 回复次数:2 
c++primer 上一句话不懂。。
为什么说:对于deque容器,如果删除时不包含第一个元素或最后一个元素,那么该deque容器相关的的所有迭代器都会失效。。。

这是为什么呢?
搜索更多相关主题的帖子: deque 元素 
2013-05-22 19:48
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
deque是两端开口的容器,中间是不能操作的
去看看deque的实现

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-05-22 21:33
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
不知道他这句话是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.
2013-05-23 08:40
快速回复:c++primer 上一句话不懂。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014173 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved