Safe to store list::iterator for later use?
2017-10-05 16:54
267 查看
转自: 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?
===========================Answer1===================================
Yes,
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
===========================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?
===========================Answer1===================================
Yes,
std::listiterators
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 not invalidate iterators to list elements, and that even removal invalidates only the iterators that point to the elements that are removed.
相关文章推荐
- How to store scaling parameters for later use
- Safe CFLAGS to use for Gentoo
- which is best to use ? List or Dictionary ? For efficiency of code execution.
- Examples of how to use Error Logging for SQL statements (Doc ID 1076042.1)
- how to use a C++ Property List (plist) serialization library (MIT license)
- 解决php It is not safe to rely on the system's timezone settings. You are *required* to use the date.
- Hive metastore database is not initialized. Please use schematool(...) to create the schema.
- RN SectionList 遇到 missing keys for items, make sure to specify a key property on each item 的 问题解决
- Hot to use typelist of Loki??
- 关于java list集合的for遍历和Iterator遍历的随想
- MySQL server version for the right syntax to use near 'type = InnoDB' at line 25
- An easy-to-use URL file downloader class for .NET
- How to delete a large number of data in SharePoint for List when refreshing data?
- Attribute listkey invalid for tag checkboxlist according to TLD
- How To Use Repadmin for Active Directory Troubleshooting
- How to deploy a .Net assmebly for COM use through CAB on Web Page (转)
- 1047.Student List for Course (25)...to be continued...
- your MySQL server version for the right syntax to use near 'NULL' at line 1
- Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications
- [MySQL] you *might* want to use the less safe log_bin_trust_function_creators variable