On Tue, Oct 10, 2017 at 4:15 PM, Simon Bürger via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> 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;
>

It will return dynamic array. it is same as:

double[5] = [0,0,0,0,0]; // this is still dynamicaly allocated.

Reply via email to