Range objects and fancy indexing -- Re: Removing elements from dynamic arrays?
peylow at gmail.com
Wed Nov 1 07:17:58 PST 2006
Bill Baxter skrev:
> Note that if 3..5 returned a range object, then there would be no real
> need for the opSlice methods. They would be replaced by opIndex
> overloaed for the range type. E.g opIndex(range r)
I cut most of it, as you know what I am referring to anyway :).
Ranges and sets are related, in fact in my own sets implementation I
have four kinds of sets:
- finite sets
- range sets
- computer sets
- functions sets
This implantation is however an overkill, and way too slow, as it also
covers infinite sets. For a compiler feature finite sets is the only
realistic goal. But having a infinite set solution as well in the
standard lib is good too.
I think you should be able to have sets of any type, and ranges of any
numeric type. For obvious reasons finite sets of integers can be
optimized greatly if used having a special case. And in worst case, I
can live with only them (As they make up for 99% of real world cases and
a templete implementation can fix the rest).
I would suggest declaring a set as this:
int<> foo = <1,2,3>;
char<> bar = <'a'..'z', 'A'..'Z'>;
How a range type can be declared, I am not sure. Writing the literals is
obvious with the .. operator. But for declaring?
int.. foo = 1..42;
Just does not look right :).
And yes, having sets and ranges solve many problems. More than a handful
of the suggestions of the D wish list page, are solved easily and
consistent using ranges or sets. Well conceptually solved, then comes
the problem of actually implementing it is the compiler :/.
But I like the idea of a few universal components that fits together in
infinite ways, better than exceptions, and special cases, that only
solves a single problem.
// Fredrik Olsson
More information about the Digitalmars-d-learn