Separate slices and dynamic arrays

monkyyy crazymonkyyy at gmail.com
Wed Jul 31 23:07:14 UTC 2024


```d
int[3] foo;
int[] bar=foo[];
bar[1]=3;
assert(foo[1]==3);//works, bar is a reference to foo
bar~=5;//oh no
bar[2]=4;
assert(foo[2]==4);//failure, bar stopped being a reference to foo
```

slices are sometimes better pointer math or sometimes gc'ed 
managed memory. This is unsafe and lacks clear ownership.

So two parts:

Introduce `int[?]` as a dynamic array, it "owns" the memory and 
duplicates on assignment from slices.

Deprecate append to slices.

`auto bar=foo[];` would still be a slice


More information about the dip.ideas mailing list