spir <denis.s...@gmail.com> wrote:

On Wed, 22 Dec 2010 23:22:56 -0600
Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

I'm thinking what to do about iota, which has good features but exacts
too much cost on tight loop performance. One solution would be to define
iota to be the simple, forward range that I defined as Iota2 in my
previous post. Then, we need a different name for the full-fledged iota
(random-access, has known length, iterates through the same numbers
forward and backward etc). Ideas?

I would keep length and add an opIn: if (e in interval) {...}. (I'm unsure whether it's worth allowing different types for bounds and/or for step; I'd rather make things simple.) Then, you could call it Interval, what do you think?

Note: The result would be very similar to python (x)ranges. D has a notation for a slightly narrower notion: '..'. Thus, what about:
        Interval!int interval = 1..9;
or else:
        auto interval = Interval!int(1..9);
?

What kind of thingie does "i..j" actually construct as of now?

Nothing. The syntax only works in foreach and opSlice.

However, this works:

final abstract class Intervals {
    struct Interval( T ) {
        T start, end;
    }
    static Interval!T opSlice( T )( T start, T end ) {
        return Interval!T( start, end );
    }
}

auto intInterval = Intervals[1..2];
auto stringInterval = Intervals["foo".."bar"];



--
Simen

Reply via email to