Move Constructor Syntax
Arafel
er.krali at gmail.com
Wed Oct 16 20:06:28 UTC 2024
On 16/10/24 20:21, Timon Gehr wrote:
> Yes, I think the sane design is that if you pass an lvalue to an rvalue
> parameter, that results in a copy (during argument passing), and the
> copy is destroyed when it goes out of scope in the constructor.
>
> So if you explicitly call an rvalue constructor, that would behave the
> same as previously.
>
> Even with the unamended DIP1040, I think assertion failures would not
> fire in your example. The way DIP1040 might break such code is if `S`
> has a destructor.
I guess that would be workable iff templated constructors are excluded
from being considered move constructors, otherwise there could be cases
where a move constructor is found that was never meant as such.
Would a way of explicitly requesting a move, like `__rvalue`, be
available in case the compiler's detection mechanism of last use needs
to be overridden?
All in all, I still see no such big benefit in changing the meaning of
existing valid code, when adding new syntax would be much clearer all
around.
Of course, it would be different if we were designing the language from
zero now, or if it were part of D3... then I might even find it an
elegant solution.
More information about the Digitalmars-d
mailing list