Subject: Re: [boost] [shared_array] Why not in C++11 ?
From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2013-07-05 21:42:39
On Fri, Jul 5, 2013 at 4:28 PM, Jens Weller <JensWeller_at_[hidden]> wrote:
> Actually its already supported, but you'll need a custom deleter:
No, it is not. Not in the way we mean. std::unique_ptr supports T and
allows operator but std::shared_ptr does not. Boost's boost::shared_ptr
is different to std::shared_ptr in this regard (as of 1.53.0).
boost::shared_ptr<T> is like std::unique_ptr<T> in that you now have
operator instead of operator->. With boost::shared_ptr<T> you can
access array elements with p[index]. With std::shared_ptr<T> you only have
operator-> so if you used it for an array, you'd have to use .get() first
and then access array elements with operator. i.e. p.get()[index].
And, as I mentioned in the other e-mail, std::shared_array has no
make_shared or allocate_shared. I have added support for make_shared<T>
and allocate_shared<T> for boost::shared_ptr<T> so again,
boost::shared_ptr should be preferred if you want an efficient way to do
boost::shared_array<T> p(new T[size]) is two allocations while
boost::shared_ptr<T> p = boost::make_shared<T>(size); is one allocation.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk