Hi All,

I am trying to convert a 1D array to a 2D array using to! and was wondering if someone could explain to me why this first example works but the second example does not compile:

Example 1:
~~~
import std.conv;
long[4] a=[1,2,3,4];
int[2][2] b = to!(int[])(a);
assert(b == [[1,2],[3,4]]);
~~~~

Example 2:
~~~
import std.conv;
long[4] a=[1,2,3,4];
int[2][2] b;
b = to!(int[])(a);
assert(b == [[1,2],[3,4]]);
~~~~
Error: cannot implicitly convert expression (to(a[])) of type int[][] to int[2][].

It's like the ReturnType in to!()() for Example 1 and Example 2 is different. Is this the case and why would it be so? If not, what is happening here?

Thanks,
ed

Reply via email to