On Sunday, 8 February 2015 at 15:20:17 UTC, karl wrote:
Hi, it's a bit unwieldy to write/read this:
result = src[base .. base+size];
instead of:
result = src[base, size];

Maybe such syntax would be a welcome addition to D? I don't see it conflicting with the existing grammar, and only the 2 slicing-operators need further extending to support it.

If this is a common pattern in your code, you could write your own function to do this and call it using UFCS:

    Range slice(Range)(Range r, size_t base, size_t size)
    {
        return r[base .. base+size];
    }

    auto arr = [0,1,2,3,4,5,6,7,8,9];
    assert(arr.slice(4,2) == [4,5]);

Reply via email to