www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - I have implemented DIP1039 - Static Arrays with Inferred Length

reply xoxorwr <alien.frog.apocalypse gmail.com> writes:
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;`

But no more! PR is ready for review: 
https://github.com/dlang/dmd/pull/22623

There was a DIP for it, but honestly, the review process is way 
too stalled and convoluted, it's become over engineered for what 
is ultimately a minimal diff for a minimal feature.
Feb 23
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 23 February 2026 at 19:54:39 UTC, xoxorwr wrote:
 But no more! PR is ready for review:
Thanks for the patch, I just applied it to opend and am building a release right now. Should be ready for download in about 30 mins...
Feb 23
prev sibling next sibling parent matheus <matheus gmail.com> writes:
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

 ...

 But no more! PR is ready for review: 
 https://github.com/dlang/dmd/pull/22623

 ...
Nice feature. On Monday, 23 February 2026 at 20:25:14 UTC, Adam D. Ruppe wrote:
 On Monday, 23 February 2026 at 19:54:39 UTC, xoxorwr wrote:
 But no more! PR is ready for review:
Thanks for the patch, I just applied it to opend and am building a release right now. Should be ready for download in about 30 mins...
Wow, you (opend) are fast. =] Matheus.
Feb 23
prev sibling next sibling parent Mike Parker <aldacron gmail.com> writes:
On Monday, 23 February 2026 at 19:54:39 UTC, xoxorwr wrote:
 There was a DIP for it, but honestly, the review process is way 
 too stalled and convoluted, it's become over engineered for 
 what is ultimately a minimal diff for a minimal feature.
The old process, sure. Now in this case, where the DIP already exists, you just post the draft in the development forum for feedback, and when you think you're ready to submit, you let me know and done.
Feb 24
prev sibling parent reply Nick Treleaven <nick geany.org> writes:
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.
Feb 27
parent reply Nick Treleaven <nick geany.org> writes:
On Friday, 27 February 2026 at 11:19:15 UTC, Nick Treleaven wrote:
 - 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)`.
Sorry, `imported!std.array.staticArray!int([1, 2, 3])`.
Feb 27
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 27 February 2026 at 11:24:03 UTC, Nick Treleaven wrote:
 Sorry, `imported!std.array.staticArray!int([1, 2, 3])`.
i think you mean `imported!"std.array".staticArray!int([1, 2, 3])`
Feb 27