Multiple Template Specialization Types (in D1)?

Nick Sabalausky a at a.a
Tue Jul 1 23:47:52 PDT 2008


"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
news:g4es21$l49$1 at digitalmars.com...
> "Nick Sabalausky" <a at a.a> wrote in message 
> news:g4ejen$10a$1 at digitalmars.com...
>
>> Just for the hell of it, I tried changing all three "alias Foo_dwc(T) 
>> Foo;" to "alias Foo_dwc!(T) Foo;" (ie, added "!"):
>>
>> ----- start test2.d -----
>> public template Foo(T: char)  {alias Foo_dwc!(T) Foo; }
>> public template Foo(T: wchar) {alias Foo_dwc!(T) Foo; }
>> public template Foo(T: dchar) {alias Foo_dwc!(T) Foo; }
>>
>> private void Foo_dwc(T)(T arg) {  }
>>
>> void main(char[][] args)
>> {
>> Foo('a');
>> }
>
> Right, the bangs are necessary.
>
>> ----- end test2.d -----
>> ----- start compiler output: DMD win 1.029 -----
>> test2.d(1): template test2.Foo(T : char) is not a function template
>> test2.d(9): template test2.Foo(T : char) cannot deduce template function 
>> from argument types (char)
>> ----- end compiler output: DMD win 1.029 -----
>
> And this is the sad outcome -- once you do this, Foo is no longer a 
> function template, and so it can't have IFTI performed on it.  *sigh*
>

I'm still somewhat new to D's templates (been spending a lot of time in 
non-D development...not by choice), so I'm trying to understand exactly 
what's going on here as best as I can. Looked up "IFTI" (Implicit Function 
Template Instantiation), so I see now this method (test2.d) does work, but 
you have to explicitly instantiate the Foo template when calling the 
function:

In main:
"Foo('a');" -> "Foo!(char)('a');"

That works. The first compiler error being from line 1 threw me off, didn't 
realize that was just a result of the line 9 error below.

But could you explain how it is that Foo stops being a function template? Or 
rather, what is the compiler doing when attempting to process line 9 in both 
the broken "Foo('a');" and fixed "Foo!(char)('a');" scenarios? 




More information about the Digitalmars-d-learn mailing list