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

--- Comment #2 from Eyal <e...@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;
}

--

Reply via email to