<div dir="ltr"><div dir="ltr">On Sun, Jul 26, 2020 at 11:25 PM Adam D. Ruppe via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Another useful thing to have would be "given this argument set to <br>
a function, give me the function that would be called".<br>
<br>
This would do implicit function template instantiation and <br>
overload resolution, but yield the function instead of the return <br>
value.<br>
<br>
Imagine:<br>
<br>
void foo(int a) {}<br>
void foo(string b) {}<br>
<br>
<br>
I want to get the address of foo(string). How do you do that <br>
right now? Well, you have to loop over overloads and check the <br>
types. What a pain, but at least doable.<br>
<br>
But wouldn't it be cool if you could do<br>
<br>
&__functionOf(foo("foo"))<br>
<br>
Where the __functionOf is the magic.<br>
<br>
<br>
So far, this is kinda just a convenience, but now imagine the <br>
case of a template. Even if template reflection worked, you'd <br>
need to figure out the template arguments and that can be <br>
basically impossible given the conversions and specializations.<br>
<br>
Then<br>
<br>
&__functionOf(writeln("bar"))<br>
<br>
for example would give a void function(string). There you can do <br>
`&writeln!string`<br>
<br>
<br>
And in cases more complex than that, the compiler's logic need <br>
not be reimplemented in user cde.<br></blockquote><div><br></div><div>Write a DIP! This is a very real reflection hole that I've struggled with before too.</div><div>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.</div><div><br></div><div>I'd suggest it might just be a __traits though, rather than introducing a new magic thing.</div></div></div>