Difference between slice[] and slice
Paul Backus
snarwin at gmail.com
Wed Sep 25 20:57:29 UTC 2019
On Wednesday, 25 September 2019 at 20:36:47 UTC, WhatMeWorry
wrote:
> 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[]` is just shorthand for `waste[0..$]`. Assigning to a
slice means copying the contents of another array into the array
that slice refers to. If the lengths of the source and
destination don't match, you get an error. Since `waste[0..$]`
and `waste[0..$-1]` can never have the same length, you will
always get an error if you try to assign one to the other.
Source: https://dlang.org/spec/arrays.html#array-copying
More information about the Digitalmars-d-learn
mailing list