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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jun 8 08:09:44 PDT 2010


On 06/08/2010 10:00 AM, Simen kjaeraas wrote:
> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>
>> I finalized BinaryHeap. It's pretty cool - it builds a forward range
>> on top of a random-access range - typically T[] - or a random-access
>> container - typically Array!T.
>>
>> The difference is simple - if you build on top of a range the heap
>> can't grow beyond the size of that range. Building on top of a
>> container makes the heap growable.
>>
>> Making BinaryHeap a range is actually pretty cool - just walking the
>> heap is tantamount to lazily sorting the container. (Of course
>> BinaryHeap has primitives in addition to the four range primitives.)
>>
>> Do you agree with putting BinaryHeap in std.range (as opposed to
>> std.container)?
>
> No. Binaryheap may work like a range, and it's definitely usable as a
> range, but the associativity of my brain says it's a container.

Let me be more specific: BinaryHeap does not work like a range. It _is_ 
a range. It implements all of a forward range's primitives with the 
required semantics.

> I fear this will end up like enum for manifest constants, which behaves
> the way it should, but does not belong in that location.

But where should I put it then? I thought it would be even more 
confusing if I put something in std.container that wait a minute, is not 
a container.


Andrei



More information about the Digitalmars-d mailing list