Anonymous function syntax

Daniel Murphy yebblies at nospamgmail.com
Thu Sep 22 23:42:18 PDT 2011


"Jacob Carlborg" <doob at me.com> wrote in message 
news:j5h98l$ors$1 at digitalmars.com...
> What I'm saying is that you can ignore the returned value of a delegate 
> therefore I think it should be possible implicitly convert a delegate 
> returning a value, to a delegate returning void. The same for function 
> pointers as well. Example:
>
> void main ()
> {
>     int delegate () bar = { return 1; };
>     void delegate () foo = bar;
>
>     int a = bar(); // here we call "bar" and handles the return value
>     bar(); // here we call "bar" and ignores the return value
>     foo(); // here we call "foo", same as the line above
> }
>
I can see the appeal, but the abi makes it difficult.  As Walter said, what 
if the return value requires destruction by the caller?  What if the return 
is done through nrvo?  While they're called the same, the code generator 
handles them very differently.  If it works, it should work for all cases.
Don't forget that you can trivially convert to a delegate returning void 
with the following syntax:
void delegate () foo = { bar(); }; 




More information about the Digitalmars-d mailing list