Safe to store list::iterator for later use?
来源:互联网 发布:光伏数据采集器接法 编辑:程序博客网 时间:2024/06/05 22:49
转自: https://stackoverflow.com/questions/837267/safe-to-store-listiterator-for-later-use
===========================Ask======================================
Suppose I have a list, in which no new nodes are added or deleted. However, the nodes may be shuffled around.
Is it safe to save an iterator, pointing to a node in the list, and access it at some arbitrarily later time?
Edit (followup question): The documentation for list::splice() says that it removes elements from the argument list. Does this mean if I call splice, using the same list as arguments to the function, that existing iterators will be invalidated?
Yes, std::list
iterators are just pointers to a node. You can insert, delete (other nodes), and rearrange nodes in the list and the iterator is not invalidated.
===========================Answer2===================================
Yes.
The standard grantees that iterators into a list will not be invalidated unless the item, they point at (metaphorically speaking) is removed from the list.
From this page: http://www.sgi.com/tech/stl/List.html
Lists have the important property that insertion and splicing do notinvalidate iterators to list elements, and that even removal invalidatesonly the iterators that point to the elements that are removed.
- Safe to store list::iterator for later use?
- Safe CFLAGS to use for Gentoo
- Just Save For Later Use
- How to Use Iterator
- List Iterator for()
- Be careful to use iterator - vector.begin()
- How to use Iterator in Java
- fast & safe upgrade to PostgreSQL 9.4 use pg_upgrade & zfs
- Use Squid+Stunnel+SwitchyOmega to Setup a Safe Proxy
- Use SharePoint Designer 2010 to implment a fuzzy query for SharePoint 2010 custom list
- which is best to use ? List or Dictionary ? For efficiency of code execution.
- List for iterator 迭代 效率 比较
- for,list,iterator,map的访问
- List遍历:for,foreach还是Iterator?
- How to close Magento store for maintenance?
- HBase waiting for dfs to exit safe model
- use python to get file list
- What NoSQL Store Should I Use? The Right Tool for Your Use Case
- fill (贪心)
- Leetcode:Maximal Square & Maximal Rectangle
- 记住企业与股票之间总是有差距的
- JDBC数据源(DataSource)的简单实现
- 关于const 修饰变量、引用、指针的说明
- Safe to store list::iterator for later use?
- HDU-4267-A Simple Problem with Integers-(树状数组)
- Redis安装和配置
- 怎样让一段代码在主函数之前执行
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C.Sum(找规律)
- Java多线程之队列Quene-yellowcong
- pycharm中配置pyqt4环境
- Uva 1153 Keep the Customer Satisfied(贪心)
- HDU 1078 FatMouse and Cheese (dfs + dp记忆化搜索)