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

Paul Backus <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #3 from Paul Backus <[email protected]> ---
The problem is not the lambda's parameter, but its return value.

Essentially, we would like the lambda to return by `ref` when `r.front` returns
by `ref`, so that it does not create an unnecessary copy. For a normal
function, the solution would be to use `auto ref`, but the lambda syntax does
not support this (issue 21243), so we must either fix that issue first or find
a workaround.

One workaround is to use a string mixin, like this:

private enum getFrontLambda = q{(return ref R r) => r.front};

enum bool isInputRange(R) =
    /* ... */
    && (
        is(typeof(mixin("ref ", getFrontLambda)))
        || is(typeof(mixin(getFrontLambda)))
    )
    /* ... */

This essentially replicates the logic of inferring `ref` in user code: attempt
to compile with `ref`, then fall back to non-`ref` if it fails.

--

Reply via email to