<div dir="ltr"><div dir="ltr">On Sun, Oct 6, 2024 at 3:06 PM Walter Bright via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">```<br>
struct S { ... }<br>
<br>
this(ref S) // copy constructor<br>
this(this) // postblit<br>
this(S) // move constructor<br>
~this() // destructor<br>
<br>
alias T = S;<br>
this(T); // also move constructor<br>
<br>
alias Q = int;<br>
this(Q); // regular constructor<br>
```<br>
As the above illustrates, a move constructor cannot be distinguished from a <br>
regular constructor by syntax alone. It needs semantic analysis.<br>
<br>
While this seems simple enough, it isn't I have discovered to my chagrin. The <br>
overload rules in the language (including things like rvalue references where <br>
sometimes an rvalue becomes an lvalue) that the move constructors get confused <br>
with the copy constructors, leading to recursive semantic loops and other problems.<br>
<br>
I've struggled with this for days now.<br>
<br>
A fix that would simplify the language and the compiler would be to have a <br>
unique syntax for a move constructor, instead of the ambiguous one in the <br>
proposal. That way, searching for a copy constructor will only yield copy <br>
constructors, and searching for a move constructor will only yield move <br>
constructors. There will be a sharp distinction between them, even in the source <br>
code. (I have seen code so dense with templates it is hard to figure out what <br>
kind of constructor it is.)<br>
<br>
Something like one of:<br>
```<br>
1. =this(S)<br>
2. this(=S)<br>
3. <-this(S)<br>
```<br>
?<br>
<br>
It may take a bit of getting used to. I kinda prefer (1) as it is sorta like <br>
`~this()`.<br><br></blockquote><div><br></div><div> as somebody who had to look up what a move constructor was.<br></div><div>So coming from a newb perspective.<br></div><div><br></div><div>My suggestion for a new syntax would be <br><br></div><div>*this(S) <br><br></div><div>as long as that doesn't screw up language analysis in other places, since there is an association between linking to the original data in the move constructor and pointers.<br><br></div><div>I think the existing syntax is cleaner though if you can make it work.<br></div><div><br><br></div></div></div>