to! converting 1D to 2D array
ed
growlercab at gmail.com
Tue Mar 11 18:54:23 PDT 2014
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
More information about the Digitalmars-d-learn
mailing list