Deprecate assigning a slice to a static array?
Salih Dincer
salihdb at hotmail.com
Wed Aug 31 15:36:54 UTC 2022
On Wednesday, 31 August 2022 at 12:04:10 UTC, Nick Treleaven
wrote:
> I didn't know initializing a static array from a slice of
> unknown length was allowed until I saw:
> https://dlang.org/blog/2022/06/21/dip1000-memory-safety-in-a-modern-system-programming-language-pt-1/
>
The reverse is also possible and note that .capacity is 0 in any
case.
```d
// D 2.0.83
import std.stdio;
void main()
{
int[4] abcd = [0, 1, 2, 3];
int[] slice = abcd[];
slice.writeln(": ", slice.capacity);
int[] dcba = [ 7, 6, 5, 4, 3, 2, 1, 0];
int[4] arr = dcba[4..$];
arr.writeln(": ", arr.capacity);
arr = dcba[0..4];
arr.writeln(": ", arr.capacity);
}/*
[0, 1, 2, 3]: 0
[3, 2, 1, 0]: 0
[7, 6, 5, 4]: 0
Process finished.
*/
```
SDB at 79
More information about the Digitalmars-d
mailing list