UFCS and delegates

Steve Teale steve.teale at britseyeview.com
Sat Mar 15 05:31:26 PDT 2014


On Saturday, 15 March 2014 at 11:02:08 UTC, Daniel Murphy wrote:
> "Steve Teale"  wrote in message 
> news:uhledfeisciwpvtvmhbp at forum.dlang.org...
>
>> Yes, I'm asking for the wrong thing. What I should have said 
>> is that given UFCS, should there be an alternate way of 
>> initializing a delegate, something along the lines of:
>>
>> void delegate(int) dg = (a, &bar);
>>
>
> Well, if you know the instance, you can do this:
>
> void delegate(int) dg = (int v) { a.bar(v); }
>
> But this would have to go inside main.

This seems a long way around the houses, is difficult to 
understand, and the result is a delegate with a frame pointer for 
the main function, which then has a nested function

void anon(int v) { a.bar(v); }

which somehow does not feel right, and if the compiler isn't 
clever, seems like another level of indirection.

Syntax like this (changed my mind ;=)) would be nice:

void delegate(int) dg = &a.bar;

I'm not particularly looking for a way of doing it at this 
moment, just whether it's something that could be done in the 
future.


More information about the Digitalmars-d mailing list