.dup with twodimensional arrays

berni someone at somemail.de
Wed Mar 21 09:59:52 UTC 2018


I need code, that generates a copy of a twodimensional array.

What I do is:

> auto tmp = new int[][](X,X);
> foreach (i; 0..X) tmp[i] = solution[i].dup;
> 
> solutions ~= tmp;

because solutions ~= solution.dup obviously doesn't work (the 
refs are copied, not the elements of the inner arrays).

Is there a better solution without this extraneous tmp variable? 
Im thinking of something like

> solutions ~= solution.nice_phobos_function_id_dont_know.dup;

or something similar?


More information about the Digitalmars-d mailing list