On Sun, 18 Sep 2011 22:37:03 +0200, Timon Gehr <timon.g...@gmx.ch> wrote:

On 09/18/2011 10:21 PM, dsimcha wrote:
On 9/18/2011 4:16 PM, Timon Gehr wrote:
What would it return?

A dummy type, e.g.:

struct Repeat(T) {
T val;
T front() @property { return val; }
void popFront() {}
enum empty = false;

static struct Dollar {}
Dollar opDollar() {
return Dollar.init;
}


auto opSlice(size_t lower, Dollar dollar) { return this; }
}

void main() {
auto r = Repeat!int(1);
auto r2 = r[666..$];
}

Ok, but what about

void main(){
     auto r = Repeat!int(1);
     auto r2 = r[666..$-1]; // ok, return entire range
     auto r3 = r[666..$/2]; // ditto
     auto r4 = r[666..$<100?$:100]; // ???

Compile-time error. struct Dollar does not have an overloaded <
operator. Or you make one that always returns false, in which case
things are a bit more complex (Dollar and 100 do not have a common
type).


     // those could be made illegal:
     auto r5 = r[666..$*0]; // ???
     auto r6 = r[666..$-$]; // ???
     auto r7 = r[666..2*$-$]; // ???
     auto r8 = r[666..($*$)%4==3?667:668]; // ???
}

They already are. The supplied Dollar struct does not have overloaded
operators for any of those operations. If you implement them, you can
have them do whatever you feel is right.

--
  Simen

Reply via email to