Default template parameters and IFTI

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Sat Aug 13 23:37:27 PDT 2011


Today, I was very surprised to discover that the following compiles and 
works:

    void foo(int i = 123, T)(T x)
    {
        import std.stdio;
        writeln(i, T.stringof, x);
    }

    void main()
    {
        foo(456.0);  // Prints "123double456"
    }

In other words, the compiler allows you to specify a default value for a 
function template parameter which is *not at the end of the parameter 
list* as long as the remaining parameters are automatically deduced.

Now, my question is:  Is this by design?  If so, I think it would be 
awesome, and I can put it to good use in the new std.path.  I do, 
however, not want to base my code on a compiler bug.

-Lars


More information about the Digitalmars-d mailing list