Boost logo

Boost :

Subject: Re: [boost] make_shared_array
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2012-11-02 20:01:01


On Fri, Nov 2, 2012 at 11:47 AM, Peter Dimov <lists_at_[hidden]> wrote:
> Nathan Crookston wrote:
>>
>> Interesting. If/when the code is ready to view, I'd be curious to see
>> how it's accomplished.
>
>
> Voila:
>
> https://svn.boost.org/trac/boost/changeset/81149
Very slick. Compiler errors for using operator* on a shared_ptr<T[]>
are a little circuitous, but not too bad. . . though once everyone has
a compiler-implemented static_assert such errors will be nicer.

I assume that, using the aliasing constructor, I'll be able to write
something like the following:
shared_ptr<int[]> a1(new int[500]);
shared_ptr<int[]> a2(a1, &a1[250]);
a1.reset();//a2 is still okay after this line.

> Glen Fernandes wrote:
>> Maybe I (and Nate) can help you with those tests.
>
>
> Thanks for the offer, but I managed. :-)
>
> You could take a look at them and see if I made some obvious mistake, since
> compile-fail tests pass if one does something stupid. :-)
They all looked good to me -- including the coverage.

I'm excited to update my code to use this.

A few questions:
Should shared_ptr<T[]> be constructable from shared_array<T>?

It seems like the following syntax is possible (my toy code seemed to work):
shared_ptr<B> sp1 = make_shared<B>(<B ctor args>);//1
shared_ptr<B[]> sp2 = make_shared<B[]>(number_of_B);//2: Default constructed
shared_ptr<B[]> sp3 = make_shared<B[]>(number_of_B, <B ctor
args>);//3: All initialized to this.
shared_ptr<int[]> sp4 = make_shared<int[]>(number_of_ints);//4: uninitialized
shared_ptr<int[]> sp4 = make_shared<int[]>(number_of_ints, 5);//5: all
initialized to 5

Are there potential ambiguities with the previous?

Thanks again for working on this.

Nate


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