tuple of delegates requires explicit type

ag0aep6g anonymous at example.com
Wed Jun 20 15:34:09 UTC 2018


On Wednesday, 20 June 2018 at 15:19:29 UTC, DigitalDesigns wrote:
> See, what the compiler is not doing is realizing that a lambda 
> can be implicitly cast to any other lambda with the same 
> signature. If it understood that then it should have no problem 
> with casting the tuple implicitly.
>
>
>> Tuple!(void function() pure nothrow @nogc @safe)
>> Tuple!(void delegate())
>
> a function can always be cast to a delegate(delegate is a super 
> type as it inherits function in type logic)

Functions (or rather, function pointers) do not convert 
implicitly to delegates in D. `void delegate()` is not a 
supertype of `void function()` in D.

The issue is that a delegate call passes the context pointer in a 
spot where a function call passes a parameter. So a function 
pointer can't just be reinterpreted as a delegate.

The conversion could be made to work by automatically wrapping 
the function in a delegate. Walter is understandibly against that 
because of the performance implication. Alternatively, it might 
be possible to change the delegate ABI so that the parameters are 
passed the same as for function calls. Older thread about that: 
https://forum.dlang.org/post/ofc0lj$2u4h$1@digitalmars.com


More information about the Digitalmars-d mailing list