I don't like slices in D
Sean Kelly
sean at invisibleduck.org
Thu Oct 17 15:33:48 PDT 2013
On Thursday, 17 October 2013 at 18:33:01 UTC, Ali Çehreli wrote:
> On 10/17/2013 11:00 AM, Vitali wrote:
> >
> > Here a little example (it fails):
> >
> > void testSlices() {
> > int[] dArr = [10, 11, 12];
> > int[] dSlice = dArr[0..2];
> > dSlice.length++;
>
> That operation has a potential of relocating the slice.
I'd be curious to see if this would ever relocate:
int[] dArr = [10,11,12];
const(int)[] dSlice = dArr[0..2];
dSlice.length++;
It shouldn't, since growing a const slice can never clobber the
underlying array, but I don't know if the current implementation
handles this case. Still, growing a const slice seems like a
pretty useless thing to do, since you can only expect to end up
with default values at the end.
More information about the Digitalmars-d
mailing list