[core.reflect] TemplateInstance reflection

Stefan Koch uplink.coder at googlemail.com
Mon Oct 4 12:07:36 UTC 2021


On Monday, 4 October 2021 at 11:54:09 UTC, jmh530 wrote:
> On Thursday, 30 September 2021 at 22:19:33 UTC, Stefan Koch 
> wrote:
>> [snip]
>
> In the code below you can only get the target of the alias, 
> such as int and float. Would it be possible to use core.reflect 
> or something similar, to be able to get back Foo or Foo!int?
>
> ```d
> template Foo(T)
> {
>     static if(is(T == int))
>         alias Foo = int;
>     else
>         alias Foo = float;
> }
>
> void main() {
>     Foo!int x;
>     Foo!double y;
>     static assert(is(typeof(x) == int));
>     static assert(is(typeof(y) == float));
> }
> ```

You can get Foo by asking for the name "Foo"
but it won't tell you much, right now as reflecting template 
declarations is a really tricky thing, they can have hidden 
errors in them, which puts the reflector in a bad state.
Therefore I don't touch the bodies of template declarations right 
now.




More information about the Digitalmars-d mailing list