Extract template parameter at runtime?
Yuxuan Shui via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 15 15:56:54 PDT 2015
On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer
wrote:
> On 6/15/15 2:10 PM, Yuxuan Shui wrote:
>> I have a template class which is derived from a base class. Is
>> it
>> possible to extract the template parameter from a reference to
>> the base
>> class?
>
> No. You can't get compile-time information at runtime, unless
> you have stored it somewhere that runtime can read.
>
> But perhaps you can further describe your requirement, and a
> solution might be available.
>
> -Steve
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.
More information about the Digitalmars-d-learn
mailing list