Suggestion: array slice through arr[base, size]

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 10 09:52:53 PST 2015


On Sunday, 8 February 2015 at 15:28:10 UTC, Vladimir Panteleev 
wrote:
> 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];
>
> If you don't want to write "base" twice, you can write:
>
> result = src[base..$][0..size];

And if that scares you:

auto slice(T)(T[] t, size_t start, size_t len) {
     return t[base .. $][0 .. len];
}

int[] arr;
arr.slice(3, 5);


More information about the Digitalmars-d mailing list