I have implemented DIP1039 - Static Arrays with Inferred Length

Nick Treleaven nick at geany.org
Fri Feb 27 11:19:15 UTC 2026


On Monday, 23 February 2026 at 19:54:39 UTC, xoxorwr wrote:
> This is something I miss a lot whenever I come back to D from 
> other languages.
>
> There's always been that friction when dealing static arrays 
> that's very annoying
>
> - you either have to manually count elements
> - or have to tap into phobos `auto arr = [1, 2, 3].staticArray;`

```d
int[$] arr = [1, 2, 3];
```

It's OK, however:

- Doesn't work as an expression - except `(){ int[$] arr = [1, 2, 
3]; return arr; }()`, which is no better than 
`imported!std.array.staticArray!int(1, 2, 3)`.
- Requires specifying the element type, which may be a 
complicated type

I think the typical case may be not wanting to specify the 
element type. If that is correct, it would be better to have 
syntax for a static array literal. E.g. `[1, 2, 3]$`. So maybe we 
need some data about use cases before picking a solution.

Also I note that `staticArray` would be fine if it was in 
`object` (instead of various uncommon AA functions) so it didn't 
need an import.


More information about the Digitalmars-d mailing list