Typeless identifiers in templates
    Jarrett Billingsley 
    kb3ctd2 at yahoo.com
       
    Sat Apr 22 19:14:46 PDT 2006
    
    
  
"BCS" <BCS_member at pathlink.com> wrote in message 
news:e2ejn2$k2d$1 at digitaldaemon.com...
> what type should A, B, etc. be? Really all they are is compile time names. 
> What
> would be nice is a "template name" type of some sort. Any ideas for a 
> better
> solution?
I've done this with strings before, like
template foo(char[] ID1, char[] ID2)
{
 const int foo = bar!(ID1) + bar!(ID2);
}
template bar(char[] ID : "A"){  const int bar = 1;  }
template bar(char[] ID : "B"){  const int bar = 2;  }
void fn()
{
 int i = foo!("A", "B"); // resolves to 3
 writefln(i);
}
That works.
    
    
More information about the Digitalmars-d-learn
mailing list