<div dir="ltr"><div>FWIW; user code shouldn't contain __rvalue directly.</div><div>You can define a move function like:</div><div> ref T move(T)(ref T value) __rvalue => value;</div><div><br></div><div>Then you can do:</div><div> T x = var.move; // move construction</div><div><br></div><div>`forward` can be implemented similarly.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, 24 Apr 2025 at 18:26, Jiten Devlani via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm exploring the new `__rvalue` expressions, and got stuck while <br>
creating a move constructor for a container(non-copyable) with a <br>
non-copyable container property.<br>
<br>
```d<br>
import core.stdc.stdio : printf;<br>
import core.memory : pureMalloc, pureFree;<br>
struct S {<br>
@("mallocd") ubyte[] p;<br>
this() @disable;<br>
this(this) @disable;<br>
this(ubyte[] p) @nogc @trusted nothrow {<br>
printf("Base constructor!\n");<br>
this.p = p;<br>
}<br>
<br>
this(S rhs) @nogc @trusted nothrow {<br>
printf("Move constructor!\n");<br>
p = rhs.p;<br>
rhs.p = null;<br>
}<br>
<br>
~this() pure @nogc @trusted nothrow {<br>
if (p) {<br>
pureFree(p.ptr);<br>
p = null;<br>
}<br>
}<br>
}<br>
<br>
struct Container {<br>
S s;<br>
this() @disable;<br>
this(this) @disable;<br>
this(S s) @nogc @trusted nothrow {<br>
this.s = __rvalue(s);<br>
}<br>
<br>
this(Container rhs) @nogc @trusted nothrow {<br>
this.s = __rvalue(rhs.s);<br>
}<br>
}<br>
```<br>
<br>
Above code results in compilation error:<br>
```<br>
<source>(35): Error: struct `example.S` is not copyable because <br>
it has a disabled postblit<br>
this.s = __rvalue(rhs.s);<br>
```<br>
<br>
I've looked into the language reference but could not find a way <br>
to move a property of a rvalue object instance.<br>
</blockquote></div>