Boost logo

Boost :

Subject: Re: [boost] [shared_array] Why not in C++11 ?
From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2013-07-05 21:35:27


> On Fri, Jul 5, 2013 at 4:09 PM, niXman <i.nixman_at_[hidden]> wrote:
>
> 2013/7/6 Glen Fernandes
> > Even in Boost, as of 1.53.0, shared_ptr<T[]> is a better alternative
than
> > shared_array<T>.
>
> Why?

Because it is consistent with unique_ptr now. You have unique_ptr<T> which
has operator-> and unique_ptr<T[]> which has operator[]. Now (as of Boost
1.53.0) you have shared_ptr<T> which has operator-> and shared_ptr<T[]>
which has operator[].

Furthermore, I also contributed boost::make_shared and
boost::allocate_shared for T[] and T[N]. See:
http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/make_shared_array.html

These do not exist for Boost shared_array, thus prefer Boost shared_ptr
with T[] or T[N] for arrays if you want an efficient way to create a shared
array: i.e. single allocation with shared_ptr<T[]> p =
make_shared<T[]>(size), instead of two allocations with shared_array<T>
p(new T[size]).

Glen


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