to! converting 1D to 2D array

Chris Williams yoreanon-chrisw at yahoo.co.jp
Wed Mar 12 17:15:18 PDT 2014


On Wednesday, 12 March 2014 at 03:37:49 UTC, ed wrote:
> My understanding of your explanation is that it shouldn't work.

It shouldn't and probably isn't working. If nothing else, when 
you use to!(x)(y), "x" should be the type that you're trying to 
convert into. So I would expect your code to be 
to!(int[2][2])(a). I would still be impressed if that worked, 
since std.conv is intended more for parsing strings into ints and 
stuff, not for splitting and grouping arrays.

Your assertion probably succeeds because in memory a two 
dimensional array is arranged with the first row followed by the 
second row. So a flat array of four items and a 2-D array of two 
arrays of two items end up laying out the same in memory. Some 
how it's going straight to memory and comparing them that way 
(maybe).


More information about the Digitalmars-d-learn mailing list