Can you move a disabled this(this) struct in to a container type if it's an rvalue?

aliak something at something.com
Thu Dec 13 09:51:42 UTC 2018


Ie:

struct S {
     @disable this(this);
     this(int i) {}
}

struct Container(T) {
     T value;
     this(T value) {
         this.value = value;
     }
}

void main() {
     auto a = Container!S(S(3)); // can't do this.
}

I can build a custom constructor for Container that makes this 
work:

static auto construct(Args...)(auto ref Args args) {
     import std.algorithm: move;
     auto value = T(args);
     auto opt = Container!T.init;
     opt.value = move(value);
     return move(opt);
}

And then "auto a = Container!T.construct(3);" works.

But is there a way to do it without adding a custom constructor 
type?

Cheers,
- Ali


More information about the Digitalmars-d-learn mailing list