Boost logo

Boost Users :

From: Michael Davis (mdavis_at_[hidden])
Date: 2002-05-30 13:11:32


There is an implementation of the method you described (const and non-const
versions of operator-> and operator*) at the following website:
 
http://ootips.org/yonat/4dev/

Perhaps this guy might be talked into submitting it.

-----Original Message-----
From: Mark Storer
To: 'Boost-Users_at_[hidden]'
Sent: 5/30/2002 1:35 PM
Subject: [Boost-Users] shared_ptr and lazy copy

Is there an easier way to use shared_ptr as a lazy copy method?

It seems to me that the only way to do it would be by testing unique()
(or
use_count()) every time the pointed-to object was to be changed:

boost::shared_ptr<foo> bar(new foo);
boost::shared_ptr<foo> baz = bar;

if(!baz->unique())
        ... // make a deep copy
baz->ChangeAFoo();

I can't think of a good way to alter shared_ptr either. The only thing
I
came up with would be const and non-const versions of operator-> and
operator* where the non-const versions checked unique() and made a deep
copy. This would seem to fall into that last question in the FAQ
anyway...
"Why doesn't shared_ptr provide (your pet feature here)". I'd think
this
could easily lead to unnecessary deep copies unless the programmer took
explicit steps (lots of const_cast's) to avoid it.

Am I missing anything?

--Mark Storer
  Software Engineer
  Cardiff Software

#include <disclaimer>
typedef std::disclaimer<Cardiff> Discard;

Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
 

Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net