IFTI Bug

Kramer Kramer_member at pathlink.com
Sun Jul 9 22:14:36 PDT 2006


Kirk McDonald wrote:
> Kramer wrote:
>> I imagine this should work.  The factorial code is straight from the 
>> docs.
>>
>> import std.stdio;
>>
>> void main()
>> {
>>     writefln(factorial(2));
>> }
>>
>> template factorial(int n)
>> {
>>   static if (n == 1)
>>     const factorial = 1;
>>   else
>>     const factorial = n * factorial!(n-1);
>> }
>>
>> C:\code\d\src>dmd template_ex_1.d
>> template_ex_1.d(8): template template_ex_1.factorial(int n) is not a 
>> function template
>> template_ex_1.d(5): template template_ex_1.factorial(int n) cannot 
>> deduce template function from argument types (int)
>>
>> -Kramer
> 
> You need to instantiate the template with a bang:
> 
> void main() {
>     writefln(factorial!(2));
> }
> 
> IFTI only applies to function templates, which this is not.
> 

Thanks.  I knew about the bang, but figured IFTI would be able to handle 
this and would consider this a function so I thought it might work.  I 
haven't worked with D in a while, so is there any reason why this isn't 
considered a function template?  What would I need to do so IFTI would 
be invoked?

Thanks in advance.

-Kramer



More information about the Digitalmars-d-bugs mailing list