<div dir="auto"><div dir="auto">I feel like we discussed exactly this at dconf fairly extensively, with pictures and diagrams and stuff...</div><div dir="auto"><br></div>Just write `T move(ref T)` as an intrinsic.<div dir="auto">There's potentially more work to do than this operation; the intrinsic will also (in the future) include internal logic to end the lifetime of the memory region, and possibly logic to record the transfer of ownership for the value. This is all not expressible in-language... it's most appropriate as an intrinsic; this is mega-fundamental stuff. Remember, the goal is to murder core.lifetime with fire.</div><div dir="auto"><br></div><div dir="auto">We don't want a function for this, no call/ret, do not want to pollute the program flow in that way and definitely don't want to create weird program flow while stepping through code while debugging. Intrinsic that initially just strips off ref, and can be enhanced with lifetime management logic in future.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 1 Oct 2024, 02:11 Walter Bright via Digitalmars-d, <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've been implementing move constructors. They are working, at least on my test <br>
cases so far. They are distinguished by a copy constructor takes its argument by <br>
ref, and a move constructor by value:<br>
<br>
```<br>
struct S<br>
{<br>
     this(ref S); // copy constructor<br>
     this(S);     // move constructor<br>
}<br>
```<br>
So far, so good. Consider:<br>
```<br>
void phone(S s)<br>
{<br>
     S t = s;  // copy constructor<br>
}<br>
```<br>
But what if we want to initialize `t` via a move constructor? Somehow, `s` has <br>
to be converted from an lvalue to an rvalue. This is done via the function rvalue():<br>
```<br>
S rvalue(ref S s) { return s; }<br>
<br>
S t = rvalue(s);<br>
```<br>
Unfortunately, rvalue() gives us this:<br>
```<br>
S __copytmp = 0;<br>
this(&__copytmp,&s);  // copy construction of s<br>
*__H1D1 = __copytmp;<br>
return __H1D1;<br>
```<br>
which is correct, but not what we want, which is:<br>
```<br>
return &s;<br>
```<br>
and also not pass an extra hidden parameter for the return value, aka __H1D1.<br>
<br>
I have thought of several ways to do this, none of which seem particularly <br>
attractive as they are all not expressible in conventional D. I won't say what <br>
they are in order to not bias anyone.<br>
<br>
So, does anyone have any brilliant ideas for how to make the compiler treat an <br>
lvalue as an rvalue?<br>
<br>
P.S. C++ uses the std::move function to do it:<br>
<br>
<a href="https://learn.microsoft.com/en-us/cpp/standard-library/utility-functions?view=msvc-170#move" rel="noreferrer noreferrer" target="_blank">https://learn.microsoft.com/en-us/cpp/standard-library/utility-functions?view=msvc-170#move</a><br>
<br>
which relies on rvalue references:<br>
<br>
<a href="https://learn.microsoft.com/en-us/cpp/cpp/rvalue-reference-declarator-amp-amp?view=msvc-170" rel="noreferrer noreferrer" target="_blank">https://learn.microsoft.com/en-us/cpp/cpp/rvalue-reference-declarator-amp-amp?view=msvc-170</a><br>
<br>
which is a major feature which I prefer to avoid.<br>
</blockquote></div>