Automatic static array length

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 26 22:34:02 UTC 2018


On 12/26/18 5:23 PM, Your Name wrote:
> Is there a way to declare a static array with an automatic length, so 
> that it doesn't have to be manually calculated?
> 
> Perhaps something like this:
> int[auto] arr = [12, 23, 54, 653, 2, 6432, 345, 435, 26];
> 
> the current way to do it is this:
> int[9] arr = [12, 23, 54, 653, 2, 6432, 345, 435, 26];
> 
> But then you have to manually count the items, and update the number 
> each time the array is changed.
> 
> Is there any way to declare a static array with an automatically 
> inferred length?

Just added recently:

https://dlang.org/phobos/std_array.html#.staticArray

i.e.:

auto arr = [12, 23, 54, 653, 2, 6432, 345, 435, 26].staticArray;

Hm... noticed just now the table at the top of that page doesn't have 
staticArray listed.

-Steve


More information about the Digitalmars-d mailing list