IFTI reflection would be nice

Avrina avrina12309412342 at gmail.com
Sun Jul 26 17:30:40 UTC 2020


On Sunday, 26 July 2020 at 16:36:43 UTC, Adam D. Ruppe wrote:
> On Sunday, 26 July 2020 at 14:03:31 UTC, Avrina wrote:
>> You can just use cast() right now to get the overload you want.
>
> Wow, I actually did not know that.
>
> But, cast is always bleh - try `auto a = cast(void 
> function(float))&foo;`... then it calls the string one in both 
> cases, yikes...
>
>
> I can't remember the example that got me thinking about this a 
> couple weeks ago, but it was a template that could *only* be 
> used with IFTI. That's my main concern, but overload selection 
> without the pitfalls of cast would be a very nice bonus too.

That should probably be an error, there's no reason that should 
work at all. It can't select one based on the type, it shouldn't 
select any, and it looks like it just selects the first one.

You can do this which is more type safe, but again, it should an 
ambiguous error. There's no reason it should be picking string 
over int.

import std.stdio;

void foo(string) { writeln("foo(string)"); }
void foo(int)    { writeln("foo(int)"); }

void main() {
	void function(float) a = &foo;
}

Error: cannot implicitly convert expression & foo of type void 
function(string _param_0) to void function(float)


More information about the Digitalmars-d mailing list