Initializing static arrays without specifying size

Ziad hatahet at gmail.com
Sun Aug 1 15:28:09 PDT 2010


Hi all,

I was wondering how I would go about initializing a static array
without explicitly specifying how big it is, given I lay out the
contents.

For example, if I do:

int[] a = [1, 2, 3, 4, 5];
auto a = [1, 2, 3, 4, 5];

both statements would result in a heap allocated array (slice). If I
want a static array:

int[5] a = [1, 2, 3, 4, 5];

I'd have to specify the size in advance (5 in this case), which
means that adding extra elements later on would require that the
size be update.

Is there a way to let the compiler automatically determine the size
based on the argument list?


More information about the Digitalmars-d-learn mailing list