Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-03-25 07:30:48


Joe Gottman wrote:
> "Vaclav Vesely" <vaclav.vesely_at_[hidden]> wrote in message
> news:e00i2r$6a8$1_at_sea.gmane.org...

[...]

>> void ok2()
>> {
>> f(new_shared_ptr<int>(2), g());
>> }
>>
>
> Another possible advantage of new_shared_ptr mentioned by the
> article is that it could reduce the number of news required to create
> the shared_ptr from 2 to 1. In the code
> shared_ptr<int> p(new int(7));
> new is called twice: when the int is created and inside the
> shared_ptr's constructor to construct an object of a type inheriting
> from boost::sp_counted_base.

This is also what N1851 proposes, with a different spelling:
make_shared_object, make_shared_object_with_alloc, make_shared_array. It's
an additional argument in favor of new_shared_ptr instead of new_<
shared_ptr >, if nothing else. There's also the alternative of
shared_ptr<X>::create( a1, ..., aN ).


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