auto arr = [1, 2, 3] should be a static array, not a GC allocated array
Salih Dincer
salihdb at hotmail.com
Sat Jul 16 18:00:40 UTC 2022
On Saturday, 16 July 2022 at 16:44:16 UTC, Dukc wrote:
> On Thursday, 14 July 2022 at 15:26:44 UTC, Dave P. wrote:
>> D has no way to express a similar concept without being
>> horribly verbose with `.staticArray`.
>
> ```D
> import std : sa = staticArray;
> //or if you don't want to rename in the import:
> alias sa = std.staticArray;
> ```
>
```d
import std : sa = staticArray;
auto sar = [1, 2, 3].sa; // really, looks short&easy
```
Why can't we use this with the byte type?
```d
auto arr = sa!(long, [1, 2, 3]);
assert(is(typeof(arr) : long[3])); // ok
//auto noCompile = sa!(byte, [1, 2, 3]);
```
SDB at 79
More information about the Digitalmars-d
mailing list