On 25/10/2014 11:32 a.m., uri wrote:
Hi All,
I was wondering why in the code below f1() works but f2 template version
called in the same manner does not. Is there a good reason from a
language/compiler perspective?
Thanks.
uri
---
auto f1(int[2][2] m)
{
return m[0][0]*m[1][1]-m[0][1]*m[1][0];
}
auto f2(T)(T[2][2] m)
{
return m[0][0]*m[1][1]-m[0][1]*m[1][0];
}
void main()
{
auto res = f1( [[1,2],[3,4]]); // works
assert(res == -2);
res = f2([[1,2],[3,4]]); // deos not work
}
Calling f2() as done above gives the following error:
Error: cannot deduce function from argument types !()(int[][]),
candidates are:
f2(T)(T[2][2] m)
res = f2(cast(int[2][2])[[1,2],[3,4]]);
Should work.
I believe this the old nefarious type deduction problem for literal arrays.
Basically the array literals are not literally literals but instead
normal arrays.