Initialization of dynamic multidimensional array
Ilya Yaroshenko via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 7 08:44:51 PST 2017
On Sunday, 5 February 2017 at 20:33:06 UTC, berni wrote:
> With X not known at compile time:
>
>> auto arr = new int[][](X,X);
>> for (int i=0;i<X;i++)
>> for (int j=0;j<X;j++)
>> arr[i][j] = -1;
>
> 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.
You may want to used new ndslice for multidimensional algorithms
http://docs.algorithm.dlang.io/latest/mir_ndslice.html
More information about the Digitalmars-d-learn
mailing list