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

Timon Gehr timon.gehr at gmx.ch
Wed Dec 18 14:26:30 PST 2013


On 12/18/2013 10:11 PM, Joseph Rushton Wakeling wrote:
>
> And you have this(...) const (aka "unique"), which can be used to
> construct both immutable and mutable instances.
>
> It seems to me that this is a very natural relation to the existing
> interpretation of mutable, immutable and const variables by the
> language, and e.g. the way that immutable, mutable and const function
> parameters are addressed.

The natural interpretation of a const constructor is that it constructs 
a const object directly. Such a constructor could eg. initialize a field 
declared with a mutable type using some external const reference.

void foo(const(int[]) a){
     // ...
     struct S{
         int[] a;
         this()const{
             this.a=a;
         }
     }
     // ...
}

The DIP argues that such a construct is not particularly useful and 
hence eliminates it for the purpose of using the syntax for a 
_different_ concept. There is no way to implement the above constructor 
using the new semantics.


More information about the Digitalmars-d mailing list