DIP 1018--The Copy Constructor--Final Review

Kagamin spam at here.lot
Tue Mar 5 08:09:22 UTC 2019


On Monday, 4 March 2019 at 12:59:36 UTC, Paolo Invernizzi wrote:
> Citing Andrei addition, "so forcing const on the copy 
> constructor's right-hand side would make simple copying task 
> UNDULY difficult", that I interpret as lack of plasticity in 
> the language in expressing such use case.
>
> There's the need to keep the original type of the value passed 
> to the parameters as it is, and to express that the argument 
> can't be muted in the method, BUT indirection can be taken.

That can be done with inout:

struct A
{
     int[] a;
     this(ref inout int[] b) inout
     {
         a=b;
     }
}

void f()
{
     int[] b;
     A a=A(b); //mutable ok
     const A a1=const A(b); //const ok
}


More information about the Digitalmars-d mailing list