IFTI reflection would be nice
Avrina
avrina12309412342 at gmail.com
Sun Jul 26 14:03:31 UTC 2020
On Sunday, 26 July 2020 at 13:20:40 UTC, Adam D. Ruppe wrote:
> 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.
You can just use cast() right now to get the overload you want.
https://run.dlang.io/is/n76kt3
import std.stdio;
void foo(string) { writeln("foo(string)"); }
void foo(int) { writeln("foo(int)"); }
void main() {
auto a = cast(void function(string))&foo;
auto b = cast(void function(int))&foo;
a("");
b(10);
}
More information about the Digitalmars-d
mailing list