|
-
February 22nd, 2008, 06:42 AM
#1
An intelligent iterator for std::list
Code:
typedef std::list<int> intList;
typedef intList::iterator myListIter;
intList myList;
myListIter iter = myList.begin();
while (1)
{
if (iter == myList.end())
{
myList.push_back(2);
myList.push_back(4);
myList.push_back(6);
}
}
On the first time round the loop, myList is empty. On the second time round, 3 items have been added to the list. Therefore 'iter' is no longer at the list end. However, the test if (iter == myList.end()) passes, so 3 more ints get added to the list.
Is there a way to 'reset' an iterator (or to have some kind of intelligent iterator) so that, if items get added to (or removed from) the list, the iterator keeps track of the new begin() and end() ?
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|