Anonymous function syntax
Jacob Carlborg
doob at me.com
Thu Sep 22 23:55:29 PDT 2011
On 2011-09-23 08:42, Daniel Murphy wrote:
> "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(); };
Why can't the compiler do something similar automatically. Then we won't
have the problem if a lambda returns void or a value.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list