Array Slice Ranges
BCS
BCS at pathlink.com
Fri Nov 10 09:24:00 PST 2006
Nikita Kalaganov wrote:
>>Wouldn't that be -1? But the point stands.
>
>
> Ah, yes of course.
>
>
>>Also how do you get a 0 length slice with inclusive?
>>exclusive
>>data[0..0].length == 0;
>>inclusive
>>data[0..0].length == 1;
>
>
> Hmm, why it's so important ?
int[] a, b, c;
a = ...
b = ...
// insert before i
int i = ...;
// exclusive slices
c = a[0..i] ~ b ~ a[i..$];
//vs.
// inclusive slices
if(i==0)
c = b ~ a;
else if(i == a.length)
c = a ~ b;
else
c = a[0..i-1] ~ b ~ a[i..$];
having the identity a == a[0..i]~a[i..$] is nice.
More information about the Digitalmars-d
mailing list