IFTI reflection would be nice
Adam D. Ruppe
destructionator at gmail.com
Sun Jul 26 13:20:40 UTC 2020
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.
More information about the Digitalmars-d
mailing list