Move Constructor Syntax
Arafel
er.krali at gmail.com
Wed Oct 16 13:23:53 UTC 2024
On 16.10.24 15:09, ShadoLight wrote:
>> That would make sense, but this would in turn mean that the move
>> constructor can never be invoked explicitly.
>
> What do you mean?
> s3 = S(S(2));
> ...is invoking the move constructor explicitly.
I meant the original syntax before the lowering:
s3 = S(s2)
IIRC, you say that the compiler would lower it to first a copy
constructor to create a temporary, then a move constructor on the
temporary. Thus, seen from the outside, it would keep the current
behavior (I mean, s2 would still be valid).
But what if I did want to move s2 into s3? How would I do it? Or is a
move something that cannot be forced explicitly? I didn't see this
addressed in the DIP either.
The problem I see is that you can't have it both ways with the proposed
syntax: either you can't call a move constructor manually on an lvalue
because an intermediate copy gets inserted, or you are changing the
semantics for the existing usages.
Again, perhaps move constructors are not meant to be invoked directly,
but I think the DIP should be explicit about what happens in that case,
or state that it's not allowed.
More information about the Digitalmars-d
mailing list