initializing a static array
Simon Bürger
simon.buerger at rwth-aachen.de
Tue Oct 10 14:15:07 UTC 2017
On Tuesday, 10 October 2017 at 13:48:16 UTC, Andrea Fontana wrote:
> On Tuesday, 10 October 2017 at 13:36:56 UTC, Simon Bürger wrote:
>> Is there a good way to set them all to zero? The only way I
>> can think of is using string-mixins to generate a string such
>> as "[0,0,0,0]" with exactly n zeroes. But that seems quite an
>> overkill for such a basic task. I suspect I might be missing
>> something obvious here...
>
> Maybe:
>
> double[n] bar = 0.repeat(n).array;
This works fine, thanks a lot. I would have expected `.array` to
return a dynamic array. But apparently the compiler is smart
enough to know the length. Even the multi-dimensional case works
fine:
double[n][n] bar = 0.repeat(n).array.repeat(n).array;
More information about the Digitalmars-d-learn
mailing list