On Tuesday, 7 July 2020 at 13:33:41 UTC, Paul Backus wrote:

You can make opApply a template:

    int opApply(Dg)(Dg dg)
        if (is(Dg : scope int delegate(ref E)))
    {
        // etc.
    }

Because `scope int delegate(ref E) @safe` implicitly converts to `scope int delegate(ref E)`, this version will accept both @safe and non-@safe delegates. (And likewise for the other function attributes.)

Yeah, but unfortunately then this won't work:

        foreach(elem; test) {
                assert(elem == key);
        }

you'd have to spell out the types for `elem`.

Reply via email to