Thread overview
[Issue 12893] Cannot create a SortedRange from inout array
Dec 17, 2022
Iain Buclaw
August 01, 2014
https://issues.dlang.org/show_bug.cgi?id=12893

briancschott@gmail.com changed:

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

--- Comment #1 from briancschott@gmail.com ---
Related:

import std.algorithm;
import std.stdio;

struct S
{
    void x() inout { writeln(y.map!(a => a + 1)); }
    int[] y;
}

void main()
{
    const S s;
    s.x();
}

/usr/include/dmd/phobos/std/algorithm.d(474): Error: variable
test.S.x.MapResult!(__lambda1, inout(int)[]).MapResult._input only parameters
or stack based variables can be inout
/usr/include/dmd/phobos/std/algorithm.d(427): Error: template instance
test.S.x.MapResult!(__lambda1, inout(int)[]) error instantiating
test.d(6):        instantiated from here: map!(inout(int)[])
Failed: ["dmd", "-v", "-o-", "test.d", "-I."]

--
February 10, 2016
https://issues.dlang.org/show_bug.cgi?id=12893

Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
                 CC|                            |bugzilla@kyllingen.net
          Component|phobos                      |dmd
           Hardware|x86                         |All
                 OS|Windows                     |All

--- Comment #2 from Lars T. Kyllingstad <bugzilla@kyllingen.net> ---
I think these are problems with the design of 'inout' rather than with Phobos. Perhaps it could be worked around with careful use of std.typecons.Unqual, but that seems unfeasible to do, as there are *a lot* of types that have this problem.  (Almost all ranges, for example, at least the ones that have internal caching.)

Therefore, I'm recategorising this as a DMD/spec issue.  Here's a test case that doesn't involve Phobos:

    struct Ptr(T)
    {
        T* ptr;
        alias ptr this;
    }

    Ptr!T takePtr(T)(ref T obj)
    {
        return Ptr!T(&obj);
    }

    inout(int[]) fun(inout int[] arr)
    {
        auto p = takePtr(arr);
        return *p;
    }

I wonder if we could invent a rule by which inout gets converted to const in some places.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=12893

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--