October 04, 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?

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.

October 04, 2021

On Monday, 4 October 2021 at 12:07:36 UTC, Stefan Koch wrote:

>

[snip]

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.

Tanks. I was thinking getting the name of Foo from x or y.

October 04, 2021

On Monday, 4 October 2021 at 14:00:49 UTC, jmh530 wrote:

>

On Monday, 4 October 2021 at 12:07:36 UTC, Stefan Koch wrote:

>

[snip]

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.

Tanks. I was thinking getting the name of Foo from x or y.

That isn't currently possible.
DMD rewrites that before core.reflect sees the function body.

October 04, 2021

On Monday, 4 October 2021 at 16:04:32 UTC, Stefan Koch wrote:

>

[snip]

That isn't currently possible.
DMD rewrites that before core.reflect sees the function body.

Yeah, I figured. I keep thinking about DIP 1021 (resolution of alias template parameters) and keeping that information around somehow (pragma?) seems like it would be needed in the more general case.

1 2
Next ›   Last »