|
Boost : |
Subject: Re: [boost] RFC: A better shared_array
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2011-10-16 12:22:10
>>> The current shared_array doesn't keep track of size. This greatly
>>> decreases it's usefulness. So I wrote a variant that does:
>>> http://pastebin.com/wkdLVqM1
>> I'd personally call it a shared_range.
> 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.
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).
- Rhys
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk