Discussion Thread: DIP 1040--Copying, Moving, and Forwarding--Community Review Round 1
tsbockman
thomas.bockman at gmail.com
Fri Mar 12 22:56:38 UTC 2021
On Friday, 12 March 2021 at 22:46:05 UTC, tsbockman wrote:
> As for the proposed move operator syntax - no, we do not
> currently use that syntax for move operators. None of the
> various methods of moving things call them:
> ...
> Even if I manually call S.opAssign, a copy is performed for the
> parameter, so it's *really* not a move operator.
I accidentally left out assignment in my example, but that's OK
because it requires a different example to demonstrate the copy
problem:
////////////////////////////////////
struct S {
int x;
this(int x) @safe {
this.x = x; }
this(ref typeof(this) s) @safe {
x = 0; }
void opAssign(S s) @safe {
x = -s.x; }
}
void main() @system {
import std.stdio : writeln;
import std.algorithm.mutation : move;
S s = 1, t;
t = s;
writeln(t);
}
////////////////////////////////////
Output:
S(0)
So, the opAssign does get called in that case, but it's not a
move because the copy constructor gets called first.
More information about the Digitalmars-d
mailing list