"David Jones" wrote in message
news:0B1A338441015A44AB55AAC0083EB78D64F5F0@exchange.keymark.com...
| There are a couple of reasons that std::listboost::shared_ptr is less
| than ideal.
|
| First, using the algorithms becomes cumbersome/annoying.
| Second, I would lose the ability to store iterators and then check them
| later for validity.
your first requirement fits the smart container library perfect.
your second requirement is really not there.
| Fundamentally, I don't want to be storing a "list of nodes of shared
| pointers of objects" but a "list of nodes of objects whose pointers to
| each other are shared pointers". And I want the iterators to be weak
| pointers to the nodes.
This is certainly an interesting problem senario. I have still to decide a
specialization
of my containers for smart pointers; eg, ptr_vector< boost::shared_ptr<T> >
can be made to do
what we find most important.
The question of whether to have iterator invalidation is interesting and I bet
it can be done, but is it worth the price?
Why not just stored a shared_ptr<T> instead of the iterator?
Some design alternatives could be
typedef ptr_list< shared_ptr<T> > list_t;
list_t list;
list.weak_begin(); // returns indirected iterator as you want
list.begin(); // returns normal indirected iterator
list_t::observed_ptr sp = list.observe( iterator ); // returns shared_ptr to
element
list_t::weak_observed_ptr wp = list.weak_observe( iterator ); // returns
weak_ptr to element
br
Thorsten