What does the following program do?
Shachar Shemesh
shachar at weka.io
Tue Dec 5 14:11:02 UTC 2017
import std.algorithm: move;
import std.stdio;
import std.string;
class A {
int val;
override string toString() const {
return "A(%s)".format(val);
}
}
struct B {
int val;
}
void main() {
B b = B(12);
B* bp = &b;
B* bp2;
writefln("bp=%s bp2=%s", bp, bp2);
move( bp, bp2 );
writefln("bp=%s bp2=%s", bp, bp2);
A a1 = new A();
a1.val = 42;
A a2;
writefln("a1=%s (%s) a2=%s (%s)", a1, cast(void*)a1, a2,
cast(void*)a2);
move( a1, a2 );
writefln("a1=%s (%s) a2=%s (%s)", a1, cast(void*)a1, a2,
cast(void*)a2);
B b2;
writefln("b=%s b2=%s", b, b2);
move( b, b2 );
writefln("b=%s b2=%s", b, b2);
}
Answer:
bp=7FFFAB559970 bp2=null
bp=7FFFAB559970 bp2=7FFFAB559970
a1=A(42) (7FD1B79E9000) a2=null (null)
a1=A(42) (7FD1B79E9000) a2=A(42) (7FD1B79E9000)
b=B(12) b2=B(0)
b=B(12) b2=B(12)
"move" was supposed to initialize "source" to init. This does not appear
to be the case. Is that a bug? Where?
More information about the Digitalmars-d
mailing list