<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 17 Oct 2024, 12:01 Paul Backus 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 Thursday, 17 October 2024 at 00:05:55 UTC, Manu wrote:<br>
> Special-casing the constructor is just admitting that the <br>
> overload selection mechanics are broken for **all other <br>
> function calls**... It's not a matter of 'preference'; if the <br>
> overload mechanics work properly then special casing the <br>
> constructor wouldn't even be thinkable or raised in <br>
> conversation. It's a hack; a really dumb hack which just leaves <br>
> EVERY OTHER FUNCTION broken.<br>
><br>
> The fact you have "no strong preference" surprises me, maybe <br>
> I've misunderstood some way in which this is not a hack that's <br>
> totally broken? Can you explain to me how every other function <br>
> call isn't broken under the special-case-for-move-constructor <br>
> solution? Overload selection has to work, it is basically the <br>
> meat of this whole thing... there's not really anything else to <br>
> it.<br>
<br>
The reason overload selection is broken for constructors but not <br>
for other functions is that "constructors" in D are really <br>
several different kinds of functions lumped together into a <br>
single overload set.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I can't imagine any other way. </div><div dir="auto">Here is a construction expression: </div><div dir="auto"> S(arg)</div><div dir="auto"><br></div><div dir="auto">What kind of constructor that is completely depends on arg, and it's selected by overload resolution. That expression could be a copy, or a move, or just a normal initialisation from an unrelated argument...</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">
These include<br>
<br>
1. Initialization functions<br>
2. Conversion functions<br>
3. Copying functions<br>
<br>
And in the future, we may add<br>
<br>
4. Moving functions<br>
<br>
There is no fundamental reason why these different kinds of <br>
functions should share the same name and overload set.</blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yes there is: </div><div dir="auto"> S(arg)</div><div dir="auto"><br></div><div dir="auto">That's how you initialise an S... It's not a suite of separate concepts; it's just "initialise an S", and the proper constructor is selected by overload resolution.</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"> Indeed, <br>
there are languages where they do not--in Rust, for example, <br>
conversion is done with `from` and `into`, and copying is done <br>
with `clone`, with the constructor reserved solely for <br>
initialization.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Our syntax is very clear: S(arg)</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">
It is only because D forces the programmer to combine all of <br>
these into a single overload set that the normal overload <br>
resolution mechanism is insufficient, and we need a special case <br>
to separate them again.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I still don't see it. There's no reason to separate them... why do you say they should be 'separated'? What does that even mean?</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>