struct S {}
ref S getS();
void fun(T, U)(T t, ref U u = getS)
{
}
void main()
{
fun(1);
}
./test.d(10): Error: template test.fun(T,U) does not match any function template declaration
./test.d(10): Error: template test.fun(T,U) cannot deduce template function from argument types !()(int)
Comment #1 by smjg — 2009-04-05T19:00:33Z
I'm not sure that this is supposed to work. It would appear that the process of binding template parameters to arguments happens strictly before that of applying default arguments. Moreover, even if U is given, if it's anything but S then it triggers a type mismatch on the default argument.
It would appear that you need two templates
void fun(T)(T t)
{
fun(t, getS());
}
void fun(T, U)(T t, U u)
{
}
Comment #2 by code — 2013-04-14T22:56:07Z
To me it looks like it should work. When the arity requires it, the default argument should be added to the list of function arguments before deducing the template arguments.
Comment #3 by verylonglogin.reg — 2014-07-13T10:12:25Z