|
-
July 29th, 2002, 03:38 PM
#1
Iterating over STL containers
I'm wondering if anybody has come across this issue before. I seem to run into it about once a year. I have an STL container in which I want to call some method on each of the items in the container. Think event/callback mechanism (or Observer pattern if you are a pattern buff). The problem I run into is that the container can be modified during an iteration. For instance, if the event was that the item is destroyed, the observer (listener), may want to stop receiving events on that object, and so will remove itself.
Iterators don't like the container changing during iteration.
Has anyone else had this problem before? How did you handle it? I was able to solve this, but I'd like to know if there are better solutions, or maybe a better way to handle a system like this.
Jeff
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
|