BinaryHeap is a range so it goes in std.range. Agree?

Joel C. Salomon joelcsalomon at gmail.com
Tue Jun 8 12:40:08 PDT 2010


On 06/08/2010 12:26 PM, Andrei Alexandrescu wrote:
> On 06/08/2010 10:53 AM, Simen kjaeraas wrote:
>> I hold that a range is a view that does not change the underlying data,
>> and does not store all its data.
>> That makes an array a container, which I feel is correct. It may still
>> have range functionality, and thus be both, but it should be
>> categorized as a container first.
>>
>> Are there other ranges that violate this definition?
> 
> The explanation goes as Steve puts it. A container has control over its
> topology.

>From your perspective as the library writer, perhaps.  As a user, my
criterion is this:  If I might go behind the back of the view, either to
directly access the underlying structure or to impose a different view,
then the view is a “range”; if that is unlikely than the view is itself
a structure, a “container”.

One addendum:  The fact that I can choose the underlying container does
not count as “going behind the back of the view”.  If I implement a
BinaryHeap (say) on something that wraps an on-disk file, that’s just an
implementation detail; it’s still just a variant of BinaryHeap.

—Joel Salomon


More information about the Digitalmars-d mailing list