Deducing a template argument from an aliased parameter

rcorre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 31 14:37:36 PST 2015


In the following example, it seems like the signatures of fun1 
and fun2 should
be equivalent. Both accept a Vector!(T, 2), the only difference 
is that fun2
goes through an alias.

struct Vector(T, int N) { }
alias Vector2(T) = Vector!(T, 2);

void fun1(T)(Vector!(T, 2) vec) { }
void fun2(T)(Vector2!T vec) { }

unittest {
   fun1(Vector!(float, 2).init);
   fun2(Vector!(float, 2).init);
}

Why can fun1 deduce `T`, but fun2 can't?

Failure:
"template d.fun2 cannot deduce function from argument types 
!()(Vector!(float, 2))"?


More information about the Digitalmars-d-learn mailing list