Heap: container or range?

Brad Roberts braddr at bellevue.puremagic.com
Fri Jan 30 13:39:59 PST 2009


On Fri, 30 Jan 2009, Andrei Alexandrescu wrote:

> Consider:
> 
> int[] a = [ 1, 2, 3, 4, 5];
> foreach (e; a)
> {
>    if (e == 3) break;
> }
> assert(a == [4, 5]);
> 
> Do you seriously expect that to be the case? Of course not. However, you would
> inconsistently expect this to happen:
> 
> int[] a = [ 1, 2, 3, 4, 5];
> foreach (e; take(4, a))
> {
>    if (e == 3) break;
> }
> assert(a == [4, 5]);
> 
> Ranges are modeled to correspond to slices. Slices have few operations that
> manipulate them by reference (notably the controversial ~=) and range are made
> to be unsurprising when compared to slices. They are really extensions of
> slices.
> 
> 
> Andrei

I hate to come back to naming, but I think that's a major part of what's 
causing grief here.  Take implies mutation of the input range.  How about 
'subrange' or 'subset' or 'leftmost' anything that doesn't imply removal.

Later,
Brad



More information about the Digitalmars-d mailing list