Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2008-07-28 04:56:09


On Mon, 2008-07-28 at 10:12 +0200, Daniel Frey wrote:
> On Sun, 2008-07-27 at 18:25 +0300, Peter Dimov wrote:
> > You should be able to make it work by making the appropriate make_shared
> > overload a friend:
> >
> > template< class T, class A1, class A2 >
> > friend
> > boost::shared_ptr< T > boost::make_shared( A1 const & a1, A2 const & a2 );
>
> Good idea, thanks. It would also render create() useless, since the user
> could call make_shared directly.

Just an idea when thinking of all the pain involved in allowing
shared_from_this during the construction phase with the approach we
already discussed earlier:

Would it be sensible to guarantee that if my class is derived from
enable_shared_from_this that I could call shared_from_this during the
construction phase iff it is constructed by make_shared? Would it be
possible to implement that behaviour? By making the ctors private and
make_shared a friend, the API would even disallow any other way to
construct objects, you can not write shared_ptr<X>( new X( .. ) ) by
accident, so it would IMHO be safe.

Regards, Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk