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

jfondren julian.fondren at gmail.com
Thu Jul 14 18:21:09 UTC 2022


On Thursday, 14 July 2022 at 17:57:13 UTC, Ali Çehreli wrote:
> On 7/14/22 09:50, jfondren wrote:
>
> > inferred length with a feature like `int[_] arr`.
>
> Is there a reason why that can't be added to D? I don't see any 
> downside.[1]
>
> Ali

Unfortunately _ is a valid identifier:

```d
enum _ = 3;
int[_] nums = [1, 2, 3];
assert(_ == 3);
```

>
> [1] Other than bike-shedding:
>
> - int[$]      // Not perfect because the array does not have a 
> length
>               // (yet) but $ means exactly that in other 
> contexts.

And `enum $ = 3` is an error.


More information about the Digitalmars-d mailing list