class scope virtual template functions

BCS ao at pathlink.com
Thu May 29 14:06:39 PDT 2008


Reply to Walter,

> BCS wrote:
> 
>> in my case, I need this syntax
>> 
>> this.Templet!("foo")(arg)
>> 
>> to be virtual.
>> 
>> The use case is inside of dparse where I have template code calling
>> template code.
>> 
> You could try parameterizing the class enclosing the template, rather
> than the template.
> 

I need to be able to have more than one version of the template

for a fuller example

class A
{
  void Template(char[] s: "foo")(int i) {writef("Hello %d\n", i);}
  void Template(char[] s: "bob")(int i) {writef("See ya %d\n", i);}
}

class B : A
{
  void Template(char[] s: "foo")(int i) {for(int j=0;j<i;j++) writef("Hello\n");}
  void Template(char[] s: "bob")(int i) {for(int j=0;j<i;j++) writef("See 
ya\n");}}
}

A a = someA();
a.Template!("foo")(5);
a.Template!("bob")(5); // same a, same class different function


the actual used code looks something like this:

void CallIt(T,char[] str)(T it)
{
  it.Template!(str)(arg)
}

(The reason for that form is rather complicated and irrelevant to this thread)





More information about the Digitalmars-d mailing list