Casting functions to delegates

Craig Black craigblack2 at cox.net
Sat Dec 11 21:05:05 PST 2010


Not sure if this is the de facto answer, but I found this one from back in 
the day.

R delegate(T) toDg(R, T...)(R function(T) fp) {
    struct dg {
        R opCall(T t) {
            return (cast(R function(T)) this) (t);
        }
    }
    R delegate(T) t;
    t.ptr = fp;
    t.funcptr = &dg.opCall;
    return t;
 }

-Craig 



More information about the Digitalmars-d mailing list