Difference between slice[] and slice
WhatMeWorry
kheaser at gmail.com
Wed Sep 25 20:36:47 UTC 2019
On Wednesday, 25 September 2019 at 19:25:06 UTC, Ali Çehreli
wrote:
> On 09/25/2019 12:06 PM, WhatMeWorry wrote:
>
> > I was
> > assuming that [] meant "the entirety" of the array.
>
> Assuming we're talking about D slices, Yes. (It could be a
> user-defined type with surprisingly different semantics.)
>
> > In short, is there anytime that one would want to use
> "slice[] =
> > something" syntax?I
>
> That changes element values.
Ok. But which element(s)? In my specific case, I was using [].
Is
waste[] = waste[0..$-1];
even semantically meaningful? Because the LDC compiler had no
problem compiling it.
>
> > //waste[] = waste[0..$-1]; // object.Error@(0): Array lengths
> don't
> > match for copy: 0 != 1
> >
> > waste = waste[0..$-1]; // works
>
> That makes slice refer to a different set of elements. In that
> example, the slice does not include the last element anymore.
>
> Ali
More information about the Digitalmars-d-learn
mailing list