Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-05-26 09:00:04

--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> This question, while more important than the std::less debate, has
been lost
> in the noise. I'll try to restate it.
> I want to serialize a shared_ptr to disk. (The boost.persistence
> will face the same problem.)
> When the shared_ptr exclusively owns its object, the task is
simple. I
> simply write its object to disk (how I do this is not relevant.)
> In the case where the use_count() of the shared_ptr is not 1,
however, I
> have a problem. This may be the first time I encounter a shared_ptr
> points to this object; or it might be the second or third time.

You'll have the same problem with raw pointers. Not all designs that
maintain multiple pointers to the same object will use a shared_ptr<>
to do so if strict ownership can be easily defined with out the need
for ref-counting.

> In the first case I'll have to write *p to disk, while in the
second case I
> must not write the object to disk, but merely write an identifier
that will
> tell me when deserializing that the object has already been created
and read
> and I only need to copy the shared_ptr.
> I can't currently do this using the public interface of shared_ptr,
> if I use shared_ptr::pn as a key in an associative array, the
problem is
> solved.
> I propose the following additions:
> typedef <implementation-defined> shared_ptr_id; // ==, !=, key in
> containers
> template<class T> shared_ptr_id shared_ptr<T>::id() const; //
> identifies the object
> A possible implementation would define shared_ptr_id as void const
* and
> simply return pn as id().

That's a reasonable addition, but since it doesn't solve the larger
problem I wonder about its actual usefullness?

Bill Kempf

Boost list run by bdawes at, gregod at, cpdaniel at, john at