[Issue 21243] Allow lambdas to return auto ref

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 18 21:20:41 UTC 2022


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

--- Comment #2 from Paul Backus <snarwin+bugzilla at gmail.com> ---
There is another example use-case in issue 16034.

Currently, `isInputRange` always evaluates to `false`, for ranges with
non-copyable elements, because it checks for the presence of `.front` by
attempting to compile the following lambda:

    (R r) => r.front

If `r.front` returns by `ref`, this will cause its return value to be copied,
which in turn causes compilation to fail when its type is non-copyable.

With `auto ref` lambdas, this could be fixed by changing the lambda to

    auto ref (R r) => r.front

As-is, the fix will require a more invasive change.

--


More information about the Digitalmars-d-bugs mailing list