I'm trying to make use of the fact that iterators to lists remain valid after insertions and removals (except iterators to what you just removed). Is this also true of std::list<T>::end();
Suppose I try the following:
typedef std::list<int> list_int;
list_int myList;
list_int::iterator iter = myList.end();
myList.push_back(1);
myList.push_back(2);
myList.push_back(3);
if(iter == myList.end()) {
/* do things here */
} else {
/* do different things here */
/* I don't expect this branch to ever execute */
}
This is important because elsewhere I might store a collection of iterators into this list, and I would test for validity by comparing against myList.end()
. It's important that invalid iterators remain so even after insertions and removals.