On Sun, Jul 26, 2020 at 11:25 PM Adam D. Ruppe via Digitalmars-d <digitalmars-d@puremagic.com> 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


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


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.



for example would give a void function(string). There you can do

And in cases more complex than that, the compiler's logic need
not be reimplemented in user cde.

Write a DIP! This is a very real reflection hole that I've struggled with before too.
Trying to sample all the possibilities, and then mirror the complex logic that the compiler uses to select a function to call internally is not a problem that should exist in user-space, and the compiler rules are subject to change making maintenance tricky and extremely brittle.

I'd suggest it might just be a __traits though, rather than introducing a new magic thing.