Immovable types

Stanislav Blinov via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 19 08:33:14 PDT 2017


On Wednesday, 19 April 2017 at 14:45:59 UTC, Meta wrote:
> On Wednesday, 19 April 2017 at 02:53:18 UTC, Stanislav Blinov 
> wrote:
>> Non-copyable and immovable types will have to be explicitly 
>> initialized, as if they had @disable this(), as they can't 
>> even be initialized with .init:
>
> It's an interesting idea but I can't even begin to fathom how 
> much code this would break. So much D code relies on every type 
> having a valid .init.

It should not break any existing code, unless it is using the 
syntax @disable this(typeof(this)), which, at the moment, is 
nonsensical, though not invalid.

Nor does it make .init invalid. Non-copyable immovables simply 
won't be able to explicitly initialize from it (it's an rvalue). 
We'll still be able to e.g. compare against .init, etc:

struct Immovable
{
     int value = 42;

     this(int v) { value = v; }

     @disable this(this);
     @disable this(Immovable);
}

assert(Immovable.init.value == 42);

Immovable i = 42;
assert(i == Immovable.init);


More information about the Digitalmars-d mailing list