Any way to move in @disabled this(this) type in to a wrapping template?
aliak
something at something.com
Thu Jul 25 20:38:59 UTC 2019
On Thursday, 25 July 2019 at 19:35:36 UTC, aliak wrote:
> Basically, can template W be made to handle an S that can't be
> copied?
>
> import std;
>
> static struct S {
> int i;
> @disable this(this);
> this(int i) { this.i = i; }
> }
>
> struct W(T) {
> T value;
> this(T value) {
> this.value = value;
> }
> }
>
> auto wrap(T)(T value) {
> return W!T(value);
> }
>
> void main() {
> auto a = wrap(S(3));
> }
>
> I tried doing something like:
>
> W!T construct(Args...)(auto ref Args args) {
> import std.algorithm: move;
> auto value = T(args);
> W!T w;
> w.value = move(value);
> return move(opt);
> }
So this works - are there any problems with it?
struct W(T) {
T value;
this(T value) {
static if (isMutable!T)
this.value = value.move;
else
this.value = value;
}
}
auto wrap(T)(T value) {
static if (isMutable!T)
return W!T(value.move);
else
return W!T(value);
}
Shouldn't this be happening by default? When would you not want
that to happen?
More information about the Digitalmars-d-learn
mailing list