How to convert a chunks result to a two-dimensional array

forkit forkit at gmail.com
Sat Jan 15 06:43:05 UTC 2022


On Saturday, 15 January 2022 at 03:48:41 UTC, Steven 
Schveighoffer wrote:
>
> Alternatively (with only one allocation for the int[] data):
>
> ```d
> int[][] arrayOfArrays = iota(1, 16).array.chunks(5).array;
> ```
>
> -Steve

All answers were helpful ;-)

But I like this one the best, because I find it both easier to 
remember, and easier to expand upon (i.e. for each extra [] just 
add another .chunks(val).array

e.g

int[][][] arrayOfArraysV4 = iota(1, 
16).array.chunks(2).array.chunks(3).array;

int[][][][] arrayOfArraysV5 = iota(1, 
16).array.chunks(2).array.chunks(3).array.chunks(4).array;



More information about the Digitalmars-d-learn mailing list