Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2004-12-31 10:56:42


Ernst Murnleitner wrote:
> Hello,
>
> I use boost::shared pointers and store them in a std::list. Now, I
> have some
> iterators which are stored in other classes. If items are inserted or
> deleted,
> the iterators become invalid. Is there a mechanism in the

std::list iterators will only be invalidated if the item to which the
iterator refers is erased.

> boost::libraries in
> order to update these iterators (e.g. iterators, containers)?

Nothing that I know of that directly supports that sort of design. That's
what shared_ptr's are for.

Store the shared_ptr and the std::list& (or a shared_ptr<std::list> if the
lifetime is not guaranteed), then use std::find( list.begin(), list.end(),
mysharedptr ) to get an iterator.

Or you might look into using the new multi_index library, storing a key
rather than an iterator.

Jeff Flinn


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net