Multiple Template Specialization Types (in D1)?

Nick Sabalausky a at a.a
Tue Jul 1 17:50:47 PDT 2008


"BCS" <ao at pathlink.com> wrote in message 
news:55391cb32eba48caa9a02d954116 at news.digitalmars.com...
> Reply to Nick,
>
>> Is there a way to do something like this in D1 without resorting to
>> function overloading?:
>>
>> void Foo(T : char, wchar, dchar)(T arg) {/*code*/}
>>
>
> 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) { ... }
>
>

Failed to compile. Not sure if it's a problem with the technique, a typo, an 
existing compiler bug, or a previously fixed compiler bug.

----- start test1.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');
}
----- end test1.d -----
----- start compiler output: DMD win 1.029 -----
test1.d(1): semicolon expected to close alias declaration
test1.d(1): no identifier for declarator Foo
test1.d(2): semicolon expected to close alias declaration
test1.d(2): no identifier for declarator Foo
test1.d(3): semicolon expected to close alias declaration
test1.d(3): no identifier for declarator Foo
----- end compiler output: DMD win 1.029 -----

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');
}

----- 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 -----




More information about the Digitalmars-d-learn mailing list