On Fri, 24 Oct 2014 22:32:57 +0000 uri via Digitalmars-d-learn <[email protected]> wrote:
D doesn't try to convert types on template argument deduction. what you really get from '[[1,2],[3,4]]' is (int[][]), not (int[2][2]). note that static arrays are not the same thing as dynamic arrays. for 'f1' compiler doing this behind the curtains: 'cast(int[2][2])[[1,2],[3,4]]'. but for 'f2' compiler can't do this, it must use the type that was given to it. so it tries template with 'int[][]' and fails. you can either change your template to `auto f2(T)(T[][] m)` (so it accepts dynamic arrays', or explicitly cast your array literal: `res = f2(cast(int[2][2])[[1,2],[3,4]]);`.
signature.asc
Description: PGP signature
