Transposing a static array

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 19 19:04:36 PST 2016


On 02/19/2016 06:26 PM, maik klein wrote:
 > On Saturday, 20 February 2016 at 02:22:12 UTC, Ali Çehreli wrote:
 >> On 02/19/2016 06:00 PM, maik klein wrote:
 >>> How would I transpose
 >>>
 >>> float[3][2]
 >>>
 >>> to
 >>>
 >>> float[2][3]
 >>>
 >>> with http://dlang.org/phobos/std_range.html#.transposed

 >>         auto r = arr[].map!((ref a) => a[]).array.transposed;

There is a problem there. Adding the following line

     writeln(r.array);

causes an error:

core.exception.AssertError@/usr/include/dmd/phobos/std/range/primitives.d(2207): 
Attempting to fetch the front of an empty array of float

Adding the following two lines does *not* preserve the range (first one 
does):

     writeln(r.save);
     writeln(r.save);

Did I not need (ref a) up there? I thought it would be a reference to a 
float[3] element.

 >>         writeln(r);
 >>     }
 >> }
 >>
 >> Ali
 >
 > Your "Method B" is how I did it too but how do I convert it back to a
 > static array of float[2][3]?

I don't know. :D

Ali



More information about the Digitalmars-d-learn mailing list