Deprecate assigning a slice to a static array?
Nick Treleaven
nick at geany.org
Wed Aug 31 16:14:51 UTC 2022
On Wednesday, 31 August 2022 at 15:36:54 UTC, Salih Dincer wrote:
> int[] dcba = [ 7, 6, 5, 4, 3, 2, 1, 0];
> int[4] arr = dcba[4..$];
The above conversion would also be deprecated because
`dcba[4..$]` is not one of the slice expression forms with
compile-time known length (the compiler doesn't know what `$`
is). `dcba[4..8]` could be used instead.
In case the runtime matching length check is desired with static
array initialization (i.e. check `dcba.length` is not > 8), it
would be written as:
int[4] arr; // optimizer can remove `= 0`
arr[] = dcba[4..$]; // matching length check now more obvious
> arr = dcba[0..4];
That is fine as I mentioned, it's one of the forms recognised.
More information about the Digitalmars-d
mailing list