Move Constructor Syntax
Paul Backus
snarwin at gmail.com
Thu Oct 17 01:55:04 UTC 2024
On Thursday, 17 October 2024 at 00:05:55 UTC, Manu wrote:
> Special-casing the constructor is just admitting that the
> overload selection mechanics are broken for **all other
> function calls**... It's not a matter of 'preference'; if the
> overload mechanics work properly then special casing the
> constructor wouldn't even be thinkable or raised in
> conversation. It's a hack; a really dumb hack which just leaves
> EVERY OTHER FUNCTION broken.
>
> The fact you have "no strong preference" surprises me, maybe
> I've misunderstood some way in which this is not a hack that's
> totally broken? Can you explain to me how every other function
> call isn't broken under the special-case-for-move-constructor
> solution? Overload selection has to work, it is basically the
> meat of this whole thing... there's not really anything else to
> it.
The reason overload selection is broken for constructors but not
for other functions is that "constructors" in D are really
several different kinds of functions lumped together into a
single overload set.
These include
1. Initialization functions
2. Conversion functions
3. Copying functions
And in the future, we may add
4. Moving functions
There is no fundamental reason why these different kinds of
functions should share the same name and overload set. Indeed,
there are languages where they do not--in Rust, for example,
conversion is done with `from` and `into`, and copying is done
with `clone`, with the constructor reserved solely for
initialization.
It is only because D forces the programmer to combine all of
these into a single overload set that the normal overload
resolution mechanism is insufficient, and we need a special case
to separate them again.
More information about the Digitalmars-d
mailing list