Extract template parameter at runtime?

Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 15 16:04:38 PDT 2015


On Monday, 15 June 2015 at 22:56:57 UTC, Yuxuan Shui wrote:
> On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer 
> wrote:
>> [...]
>
> Well I don't have a serious use case of this. I just started 
> using D couple of weeks ago, and is now experimenting with it 
> by writing a toy compiler.
>
> What I'm doing is I'm abusing the D type system to represent 
> types in my toy language. I store type information into 
> template parameters, and when I need to type check, I just use 
> typeid and compare the result. Now I want to generate different 
> code when I encounter different types, and for that I want to 
> get the template parameters.
>
> Of course if this is not possible I can always go back to 
> implement my own type system properly. It's just a good thing 
> to have.

Maybe I can put a virtual function in the class that return the 
template parameter?


More information about the Digitalmars-d-learn mailing list