<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 15 Oct 2024, 19:56 Arafel 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">On 15/10/24 11:26, Manu wrote:<br>
> Show me a case study; what might you do with an rvalue constructor if <br>
> not initialise an instance from an rvalue?<br>
<br>
I think one such case might be metaprogramming. Consider:<br>
<br>
```d<br>
struct S {<br>
int i;<br>
this(C)(C c) if (is(C : int)) {<br>
this.i = c;<br>
}<br>
<br>
alias i this;<br>
}<br>
<br>
void main() {<br>
S s1, s2, s3;<br>
int i = 1;<br>
s1 = S(1);<br>
s2 = S(i);<br>
s3 = S(s1); // This was most certainly not intended as a move constructor.<br>
}<br>
```<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Your example is a valid move constructor though... so even if the S(S) case were reinterpreted under the new move semantics, it's fine. It's almost impossible to imagine such an example where this isn't true.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This example might seem artificial, and it is, but just imagine any <br>
templated constructor that uses DbI, and where the own type matches.<br>
<br>
The actual inner details (i.e. that `S` is instantiated) might be even <br>
unknown to the caller, for instance if it comes from the user side of an <br>
API through a templated function using IFTI.<br>
<br>
Also, you cannot use `ref` because you want it to accept both r- and <br>
l-values, and in any case there might be good reasons why this isn't <br>
desirable in metaprogramming.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That's what auto ref is for, if this specifically is your problem... and as I described before; there's a quite likely chance that instances of this pattern in the wild were actually written by D amateurs, and the code is actually broken, or doesn't actually quite do what they think they were trying to do. </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>