Boost logo

Boost Users :

From: Ernst Murnleitner (mur_at_[hidden])
Date: 2005-01-02 05:51:40

Am Fr, den 31.12.2004 schrieb Jeff Flinn um 16:56:

> 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.

Thank you. Storing the shared_ptr and then searching the iterator would
maybe take a long time, if the list is large. Faster would be to store
the iterator and remove it if the entry is removed by erase(), but it
becomes more difficult:

I would wrap the list and the iterator in 2 new classes and store an
intrusive_ptr to the new iterator. Whenever the count of the
iterator/intrusive_ptr becomes 1 - that means, that the list or the
other class which owned the pointer, disappeared or released the
intrusive_ptr - I would erase the iterator from the remaining list or
class. In this case, the iterator has to store a shared_ptr to the list
and to the secont owner.

I will try this, otherwise I will come back to your solution.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at