IFTI reflection would be nice
Jean-Louis Leroy
jl at leroy.nyc
Sun Jul 26 19:08:01 UTC 2020
On Sunday, 26 July 2020 at 13:20:40 UTC, Adam D. Ruppe wrote:
> Another useful thing to have would be "given this argument set
> to a function, give me the function that would be called".
>
> This would do implicit function template instantiation and
> overload resolution, but yield the function instead of the
> return value.
>
> Imagine:
>
> void foo(int a) {}
> void foo(string b) {}
>
>
> I want to get the address of foo(string). How do you do that
> right now? Well, you have to loop over overloads and check the
> types. What a pain, but at least doable.
>
> But wouldn't it be cool if you could do
>
> &__functionOf(foo("foo"))
>
> Where the __functionOf is the magic.
>
>
> So far, this is kinda just a convenience, but now imagine the
> case of a template. Even if template reflection worked, you'd
> need to figure out the template arguments and that can be
> basically impossible given the conversions and specializations.
>
> Then
>
> &__functionOf(writeln("bar"))
>
> for example would give a void function(string). There you can
> do `&writeln!string`
>
>
> And in cases more complex than that, the compiler's logic need
> not be reimplemented in user cde.
Or make an alias, rather than a function pointer. That would be
more useful.
More information about the Digitalmars-d
mailing list