Casting functions to delegates

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Dec 12 03:15:18 PST 2010


On 12.12.2010 7:25, Matthias Walter wrote:
> Hi all,
>
> there was a discussion in 2006 but w/o a result, and I didn't find any
> bugs about implicitely casting functions to delegates. It seems to be
> impossible as long as function-pointer calls work differently than
> delegate calls in the ABI. Will this at some point be fixed?
>
> If not, is there a conversion function in phobos (I didn't find one)? I
> played a bit and found that this one might work:
>
> R delegate(A) funcionToDelegate (R, A...) (R function(A) func)
> {
>    return (A a){ return func(a); };
> }
>
> Matthias
There is actually almost forgotten function in std.functional - 
toDelegate, which does it in the most general way, functional objects 
covered.
Sadly enough it's not listed in docs, because of the auto return.

-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list