Thread overview
[Issue 16034] map should be possible with a reference only
May 17, 2016
ag0aep6g@gmail.com
May 19, 2016
ZombineDev
Jan 09, 2018
Alex
Sep 18, 2022
Paul Backus
Sep 19, 2022
Dlang Bot
Sep 20, 2022
Dlang Bot
May 17, 2016
https://issues.dlang.org/show_bug.cgi?id=16034

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com

--- Comment #1 from ag0aep6g@gmail.com ---
Underlying issue: isInputRange!(One[]) is false.

--
May 19, 2016
https://issues.dlang.org/show_bug.cgi?id=16034

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

--- Comment #2 from ZombineDev <petar.p.kirov@gmail.com> ---
IMO, the language limitation that ref is not part of the type (but is instead
only a storage class), prevents making ranges work (among other things) work
with non-copyable types.
If that wasn't the case ElementType!(One[]) could return ref(One), and you
could use map with a lambda whose paramter is ref(One).

--
January 09, 2018
https://issues.dlang.org/show_bug.cgi?id=16034

Alex <sascha.orlov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sascha.orlov@gmail.com

--
September 18, 2022
https://issues.dlang.org/show_bug.cgi?id=16034

Paul Backus <snarwin+bugzilla@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla@gmail.com

--- Comment #3 from Paul Backus <snarwin+bugzilla@gmail.com> ---
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.

--
September 19, 2022
https://issues.dlang.org/show_bug.cgi?id=16034

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@jamesragray updated dlang/phobos pull request #8573 "Fix issue 16034: map should be possible with a reference only" fixing this issue:

- Fix issue 16034: map should be possible with a reference only

https://github.com/dlang/phobos/pull/8573

--
September 20, 2022
https://issues.dlang.org/show_bug.cgi?id=16034

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #8573 "Fix issue 16034: map should be possible with a reference only" was merged into master:

- 41959deae627dba93a88f6c59ec9200d35684106 by james:
  Fix issue 16034: map should be possible with a reference only

https://github.com/dlang/phobos/pull/8573

--