[Issue 17156] Local function declaration not inferred to be static

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 12 08:55:17 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17156

--- Comment #2 from Eyal <eyal at weka.io> ---
I see, but this would not be a problem if function was automatically
convertible to delegate (std.functional : toDelegate).

Is there any reason that you cannot hand over functions when delegates are
expected?

I'd expect something even simpler than std.functional:toDelegate to work,
especially if done inside the compiler:

auto toDelegate(R, Args...)(R function(Args args) func) {
    struct delegate_t {
        R function(Args args) ctx;
        R function(R function(Args args), Args args) func;
    }
    static R call_func(R function(Args args) arg, Args args) {
        auto f = arg;
        return f(args);
    }
    auto del = delegate_t(func, &call_func);
    return *cast(R delegate(Args) *)&del;
}

--


More information about the Digitalmars-d-bugs mailing list