advise about safety of using move in an opAssign with __traits(isRef

Paul Backus snarwin at gmail.com
Sat Aug 17 16:43:51 UTC 2019


On Friday, 16 August 2019 at 08:07:28 UTC, aliak wrote:
> Hi, I'm trying to fix a use-case where you have a wrapper 
> template type (it's an optional) and the wrapping type has 
> @disable this(this). And having this scenario work:
>
> struct S {
>   @disable this(this);
> }
> Optional!S fun() {...}
>
> Optional!S a;
> a = fun.move;
>
> Now that won't work because of the disabled copy

Are you sure? I tried to reproduce the error you're describing, 
and I couldn't do it. The following compiles and runs without any 
issues:

struct Wrapper(T) { T value; }
struct NoCopy { @disable this(this); }

Wrapper!NoCopy fun()
{
     return Wrapper!NoCopy();
}

void main()
{
     Wrapper!NoCopy a;
     a = fun(); // already an rvalue, so moved implicitly
}

Can you give a more complete example of the problem you're having?


More information about the Digitalmars-d-learn mailing list