Boost logo

Boost :

Subject: Re: [boost] [shared_array] Why not in C++11 ?
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2013-07-08 08:50:50


Hi,

Jonathan Wakely wrote:
> On 8 July 2013 09:22, Sid Sacek wrote:
>>
>>
>>> If you want a container, use one. Containers with shared storage would be a nice addition
>>> to Boost, IMHO, but these should not abuse shared_ptr interface.
>>
>> According to what you just wrote 'shared_ptr<T[]>' has already abused 'shared_ptr<>' and
>> all of the array features should be rolled back, or be put into another class altogether.
>
> I disagree with your implication that shared_ptr<T[]> abuses anything,
> maybe your view is skewed by thinking it's trying to be something it
> isn't. shared_ptr<T> and shared_ptr<T[]> are similar to T* pointing
> to a single object, and a T* pointing to an array, with the same
> limitation that the size is not part of the pointer but with the
> advantage that you don't have to remember whether to use delete or
> delete[].
>
> Now you could argue that using pointers to refer to arrays abuses
> pointers, but that's how C++ works, and it does have many advantages.
>

And correct me if I'm wrong but as with using operator-> with a pointer
to array, there is also possible to use operator[] with a pointer to
non-array variable:

T *a = new T[1];
T *v = new T;

a->m;
v->m;
a[0].m;
v[0].m;

Boost's smart pointers implements a reasonable subset of those
operations which reflects:

v->m = 0;
a[0].m = 0;

There are no additional methods in pointers, indicating the size of
allocated storage. Smart pointers should probably be as close as
possible to the raw ones because they are pointers not containers or
buffers.

Regards,
Adam


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