So I have the following code:
void invert(T)(T[2][] arr)
{
auto result = new T[2][arr.length];
foreach (i, v; arr)
result[i] = [-v[0], -v[1]];
return result;
}
and I call it:
invert([[5, 6], [6, 7]]);
and I get:
test.d(94):Error: templatetest.invert(T)does not match any function template declaration
test.d(94):Error: templatetest.invert(T)cannot deduce template function from argument types!()(int[][])
What's the easiest way to fix this without losing the auto-inference feature?
The problem is that you can't have a literal which is a static array. You end up with a dynamic array - int[][] in this case - instead of the int[2][] that you want. The inference works just fine. It's the type that you're giving it which is wrong. You're going to have to create a variable of the correct type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With