auto arr = [1, 2, 3] should be a static array, not a GC allocated array

FeepingCreature feepingcreature at gmail.com
Tue Jul 19 14:44:52 UTC 2022


On Tuesday, 19 July 2022 at 14:04:09 UTC, Quirin Schroll wrote:
> ```D
> void main()
> {
>     auto empty = s[];
>     static assert(is(typeof(empty) == void[0]));
>
>     auto xs = s[1,cast(byte)2,3];
>     static assert(is(typeof(xs) == int[3]));
>
>     static struct NoCopy { @disable this(this); }
>     auto noCopies = s[NoCopy(), NoCopy()];
> }
> ```
> You’re free to choose any name (except keywords). If you name 
> it `stackalloc`, it almost looks like taken from C#.

I love this! Great use of multidimensional indexes. I guess you 
can think of it as `s` being an n-dimensional table of all static 
arrays.


More information about the Digitalmars-d mailing list