www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2803] New: template + default argument = doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2803

           Summary: template + default argument = doesn't work
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


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)


-- 
Apr 05 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2803


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
         OS/Version|Linux                       |All




------- Comment #1 from smjg iname.com  2009-04-05 19:00 -------
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)
{
}


-- 
Apr 05 2009