Thread overview
[Issue 9983] inout type can not be used as a parameter for structure template
Mar 06, 2018
Martin Nowak
Mar 09, 2018
anonymous4
Aug 03, 2018
anonymous4
Aug 21, 2019
anonymous4
Mar 19, 2021
anonymous4
Mar 19, 2021
anonymous4
Dec 17, 2022
Iain Buclaw
March 06, 2018
https://issues.dlang.org/show_bug.cgi?id=9983

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu
           Severity|normal                      |enhancement

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

--- Comment #1 from anonymous4 <dfj1esp02@sneakemail.com> ---
Looks like it can be solved by smart enough container constructors. See this quick PoC:
---
struct Container(T)
{
        T value;
        inout(T) get() inout
        {
                return value;
        }
}

/// Smart constructor
auto makeContainer(T)(T arg)
{
        alias E=typeof(cast()arg[0]);
        static if(is(T==inout(E)[]))
        {
                return inout(Container!(E[]))(arg);
        }
        else
        {
                return Container!T(arg);
        }
}

auto f(inout int[] a)
{
        return makeContainer(a);
}

void g(immutable int[] a)
{
        auto b=f(a);
        immutable Container!(int[]) c=b;
        immutable int[] d=c.get;
        immutable int[] e=b.get;
        //static assert(false,typeof(b).stringof);
}

void g(int[] a)
{
        auto b=f(a);
        Container!(int[]) c=b;
        int[] d=c.get;
        int[] e=b.get;
        //static assert(false,typeof(b).stringof);
}
---

--
March 13, 2018
https://issues.dlang.org/show_bug.cgi?id=9983

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
I actually went over this in my inout talk a few years ago.

a couple of points here:

1. The OP's request is invalid. There is no way for f to know what the mutability qualifier is, as inout is not a template parameter, it's a qualifier.

2. inout members should be allowed inside structs, they will work just fine. I wish they hadn't been disallowed.

The only thing you wouldn't be able to do is call a function that returns a struct with inout members with a different mutability qualifier than inout.

e.g. this should work:

inout int[] x;
auto foo = f(x); // OK, returns Foo!(inout(int))

But this shouldn't:

int[] x;
auto foo = f(x); // Error, cannot convert struct with inout members to proper
mutability.

There is no way for the compiler to know that it could potentially convert the return value to mutable T, even when it knows that Foo is a template.

We should either close this bug as invalid, or repurpose to request support for structs with inout members.

--
August 03, 2018
https://issues.dlang.org/show_bug.cgi?id=9983

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=19126

--
August 21, 2019
https://issues.dlang.org/show_bug.cgi?id=9983

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=15651

--
March 19, 2021
https://issues.dlang.org/show_bug.cgi?id=9983

anonymous4 <dfj1esp02@sneakemail.com> changed:

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

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
*** Issue 21733 has been marked as a duplicate of this issue. ***

--
March 19, 2021
https://issues.dlang.org/show_bug.cgi?id=9983

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://forum.dlang.org/pos
                   |                            |t/iywgvygrefddthlanqvl@foru
                   |                            |m.dlang.org

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--