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
> 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
> 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,
> 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
> 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
> tell me when deserializing that the object has already been created
> 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
> I propose the following additions:
> typedef <implementation-defined> shared_ptr_id; // ==, !=, key in
> 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
> 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?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk