DIP53 and DIP49 (ver2) - New definitions for qualified constructors and postblits

Timon Gehr timon.gehr at gmx.ch
Fri Dec 20 06:22:41 PST 2013


On 12/20/2013 03:04 PM, Timon Gehr wrote:
>
> The DIP breaks some existing, perfectly valid code without any clear way
> to fix it.
>
> const(int)* foo(...){ ... }
>
> class C{
>      int* a;
>      this()const{
>          a = foo(...); // error
>      }
> }

The actual workaround will be:

class C{
     int* a;
     private this(inout(int)* foo_result)inout{
         a = foo_result;
     }
}

const(C) constructC(){ return new C(foo(...)); }
// or 'new const(C)' ? If so, how to add a const constructor
// without breaking the workaround?


More information about the Digitalmars-d mailing list