Typeless identifiers in templates

BCS BCS_member at pathlink.com
Sun Apr 23 13:14:51 PDT 2006


In article <e2ensb$p0v$1 at digitaldaemon.com>, Jarrett Billingsley says...
>
>"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

I'm using enums, there not that elegant but they work.

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