<div dir="auto">One another way is use something like this:<div dir="auto">import std.array, std.algorithm, std.stdio;<br><div dir="auto">auto arr = uninitializedArray!(int[][])(ROWS,COLS);</div><div dir="auto">arr.each!"a[]=-1";</div><div dir="auto">writeln(arr);</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">Dne 6. 2. 2017 8:21 PM napsal uživatel "berni via Digitalmars-d-learn" <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sunday, 5 February 2017 at 21:14:33 UTC, Daniel Kozak wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<a href="http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361" rel="noreferrer" target="_blank">http://stackoverflow.com/quest<wbr>ions/24600796/d-set-default-<wbr>value-for-a-struct-member-<wbr>which-is-a-multidimensional-<wbr>static-arr/24754361#24754361</a><br>
<br>
<br>
Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
With X not known at compile time:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
auto arr = new int[][](X,X);<br>
for (int i=0;i<X;i++)<br>
  for (int j=0;j<X;j++)<br>
    arr[i][j] = -1;<br>
</blockquote>
<br>
Is there anything better for this? I mean, the program will fill the array with zeroes, just to overwrite all of them with -1. That's wasted execution time and doesn't feel D-ish to me.<br>
</blockquote></blockquote>
<br>
Thanks for the link. Looks a little bit hacky... I hoped for something more straightforward, or at least, if direct initialisation is not possible something like "arr[][] = -1;" or "arr[0..X][0..X] = -1;" But as far as I can see now, this does not exist.<br>
</blockquote></div></div>