Move Constructor Syntax
Timon Gehr
timon.gehr at gmx.ch
Wed Oct 16 00:43:39 UTC 2024
On 10/15/24 21:29, Arafel wrote:
>
> I had a look at it before posting, and according to it [1] (my bold):
>
> > A Move Constructor for struct S is declared as:
> >
> > ```d
> > this(S s) { ... }
> > ```
> >
> > [...]
> >
> > A _Move Constructor_ is a struct member constructor that moves,
> rather than copies, the argument corresponding to its first parameter
> into the object to be constructed. **The argument is invalid after this
> move**, and is not destructed.
You are right assuming move constructors work as shown in DIP1040.
However, I think this design is not really workable, and I think Manu is
arguing from a position of assuming that the argument needs to remain
valid and will be destroyed by default.
A benefit of `=this(ref S)` syntax or similar is that it supports the
design where the argument is not destructed without additional language
features to elide the destructor call, and without a special case where
destructor elision may be unexpected given the syntax.
However, I think it either has to leave the argument in a valid state or
explicit moves have to blit `.init` over the argument after calling the
move constructor.
More information about the Digitalmars-d
mailing list