Stupid little iota of an idea
Nick Sabalausky
a at a.a
Sat Feb 12 17:15:13 PST 2011
"Andrej Mitrovic" <andrej.mitrovich at gmail.com> wrote in message
news:mailman.1581.1297547851.4748.digitalmars-d at puremagic.com...
> I'd maybe vote for the syntax change.
>
> But maybe we could extend the array slice syntax to construct ranges:
>
> filter!`a % 2 == 0`([1..5])
> auto r = [0 .. 5];
>
> So if the slice sits on its own it becomes a range. Or is this too
> scary/ambiguous?
>
I like that. It also avoids this ambiguity:
class Foo
{
opSlice(int a, int b) {}
opIndex(R)(R r) if(isSomeRange!R) {}
}
auto f = new Foo();
f[1..5] // opSlice with ints, or opIndex with a range?
If a..b requires [] to be a range literal, then the above is unambiguously
an opSlice with ints, and calling opIndex with a range literal would be
f[[1..5]].
Not sure why anyone would ever index on a range though, outside of operator
overload abuse.
More information about the Digitalmars-d
mailing list