Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-05-26 06:56:41

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 library
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 that
points to this object; or it might be the second or third time.

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, although
if I use shared_ptr::pn as a key in an associative array, the problem is

I propose the following additions:

typedef <implementation-defined> shared_ptr_id; // ==, !=, key in assoc

template<class T> shared_ptr_id shared_ptr<T>::id() const; // uniquely
identifies the object

A possible implementation would define shared_ptr_id as void const * and
simply return pn as id().

Peter Dimov
Multi Media Ltd.

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