Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] scoped_array / shared_array (size_t) constructor
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-31 19:19:38


On Mon, Oct 31, 2011 at 11:52 PM, Richard Hadsell
<hadsell_at_[hidden]> wrote:
> On 10/31/2011 05:26 PM, Olaf van der Spek wrote:
>>
>> On Mon, Oct 31, 2011 at 9:51 PM, Andrey Semashev
>> <andrey.semashev_at_[hidden]>  wrote:
>>>
>>> I'm using it, from time to time. Frankly, I'm not sure there's much value
>>> in
>>> the suggested improvement. Smart pointers are not containers, so there's
>>> no
>>> need to follow the interface, especially considering ambiguities like
>>> boost::scoped_array<unsigned char>  A(0); (is 0 a null pointer or a zero
>>> size
>>> of the array here?). Zero sized arrays are quite valid when dynamically
>>> allocated (the allocation result is not NULL in this case), so you can't
>>> always initialize the pointer to NULL in this case.
>>
>> Why not? Does the pointer matter if the size is 0?
>
> Yes, it matters.  You can test a scoped_array to see whether anything is
> allocated.  You can't determine that its size is 0.

Don't you keep the size somewhere else? The array seems kinda useless
when you don't know the size.

> If you want to implement this feature, you would have to advertise this as a
> change in the interface, not just a new feature, because, as people have
> pointed out, 0 would map to the size constructor rather than the default
> pointer.

Yeah, that's a problem.

Olaf


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