Multiple Template Specialization Types (in D1)?
Nick Sabalausky
a at a.a
Wed Jul 2 08:19:29 PDT 2008
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:g4g3hd$ckq$1 at digitalmars.com...
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message
> news:g4g2fg$a4l$1 at digitalmars.com...
>
>>
>> In that case, this should work, but generates extra code (which should be
>> inlined):
>>
>> public void Foo(T: char)(T arg) {Foo_dwc!(T)(arg); }
>> public void Foo(T: wchar)(T arg) {Foo_dwc!(T)(arg); }
>> public void Foo(T: dchar)(T arg) {Foo_dwc!(T)(arg); }
>>
>> private void Foo_dwc(T)(T arg) { }
>>
>> void main(char[][] args)
>> {
>> Foo('a');
>> }
>
> It does. :)
I can't decide if this is better of worse. Leaning towards worse ;)
char[] Bar(char[] retType, char[] publicName, char[] privateName,
char[] argsDecl, char[] argsCall, char[][] types)
{
char[] ret;
foreach(char[] type; types)
{
ret ~= "public "~retType~" "~publicName~"(T:"~type~")("~argsDecl~")
{"~privateName~"!(T)("~argsCall~");}";
}
return ret;
}
mixin(Bar("void", "Foo", "Foo_dwc", "T arg", "arg", ["char", "wchar",
"dchar"]));
void main(char[][] args)
{
Foo('a');
}
More information about the Digitalmars-d-learn
mailing list