|
Boost : |
Subject: Re: [boost] RFC: A better shared_array
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-16 13:37:19
On Sun, Oct 16, 2011 at 6:22 PM, Rhys Ulerich <rhys.ulerich_at_[hidden]> wrote:
>> Why?
>> The class owns the content. A range does not own the content.
>
> Because the class knows its end. A shared_array does not know its
> end. And because your implementation is-an iterator_range.
That's because shared_array is handicapped. ;)
boost/std::array knows it's size. Even the size of a C array can be determined.
> Re: Peter Dimov's comment that:
>> One question you'll invariably get from people is why you don't store begin into the shared_ptr, eliminating one pointer...
>>
>> shared_ptr<T> begin_;
>> size_t size_;
>
> If one thinks of the class as a resource-owning iterator_range, I
> think a three member (shared_ptr/iterator_range) implementation gives
> more flexibility (e.g. sub range instances could track resource
> ownership against the same shared_ptr).
>
> If one thinks of the class as a shared_array with a length function,
> the two member (shared_ptr/size_t) implementation is definitely more
> space efficient. In that case, I'd personally not publicly inherit
> from iterator_range and would follow Peter's implementation suggestion
> (possibly using a shared_array instead of a shared_ptr).
Both allow sub ranges. But yeah, a 3 ptr class (begin, end and
counter) is ideal.
Olaf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk