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

jfondren julian.fondren at gmail.com
Tue Jul 19 16:25:03 UTC 2022


On Tuesday, 19 July 2022 at 15:27:57 UTC, ryuukk_ wrote:
> - having to write the helper code
> - having to tap into the std
> - having then to import this helper module everywhere
> - having to spend time doing all of the above and carry that 
> file in all my projects
...
> For something as basic as wanting an inferred fixed static 
> array length

"This is basic" isn't that persuasive, and realistically the 
solution isn't all of that but just "import the improved template 
and then use it".

Try these:

- D should be at *least* as convenient as C. Here, it is clearly 
worse.

- D should retain an advantage of fast compilation. 
Microbenchmarks easily show that compilation is slower with this 
template (and results in larger objects--larger with each 
different length and type of array).

- Do you really want someone to think about a choice like this? 
Between tediously counting the members of static arrays, or 
having faster and slimmer builds? Do you want to see a D style 
guide with such a suggestion in it?


More information about the Digitalmars-d mailing list