On Thursday, 15 March 2018 at 11:33:49 UTC, Simen Kjærås wrote:
On Thursday, 15 March 2018 at 11:18:48 UTC, Robert-D wrote:
[...]


This is where things go wrong:
    [...]

'inout' means that this function can keep the const, immutable or mutable status of the type on which the function is called. This means that an inout function has to treat the object as const, because otherwise the function would break the guarantees of immutable and const.

When using inout on a function, you always want to put inout on something else too - either a ref parameter or the return value. In your case, this works:

    inout(S) dup() inout pure {
        return inout(S)(aa);
    }

--
  Simen

I want the function to create a mutable copy from a const or a imutable

Like this:

void main() {
    const S s = S(["": ""]);
    S b = s.dup();
}

How can i do that?

Reply via email to