Go and generic programming on reddit, also touches on D

Kagamin spam at here.lot
Mon Sep 19 08:17:01 PDT 2011


Steven Schveighoffer Wrote:

> auto set = new TreeSet!uint(1, 3, 5, 7, 9);
> assert(set.length == 5);
> auto range = set[1..set.length];
> 
> assert(walkLength(range) == 2); // probably not what you expected

Where you got that "1"?
How to slice it from begin to 7?

Looks like an operator overload abuse. Slicing is an array's feature. If a collection doesn't support array interface, it's questionable whether it should support slicing as it's defined in D. By stretching slicing to non-array collections you break its semantics. Good for voodoo, bad for engineering.


More information about the Digitalmars-d mailing list