this(this) / opAssign
Era Scarecrow
rtcvb32 at yahoo.com
Thu Jan 10 15:29:51 PST 2013
On Thursday, 10 January 2013 at 23:03:30 UTC, Namespace wrote:
> Is it expected behaviour that this code compiles and prints:
I think it is. Postblit 'this(this)' occurs while initializing a
variable from one, rather than copying. Which you also can
compare against move symantics.
Correct me if i'm wrong.
struct S {
this(this) {writeln("this(this)"); }
void opAssign(ref S s) {writeln("opAssign ref/copy");}
void opAssign(S s) {writeln("opAssign move");}
}
//postblit
S s1;
S s2 = s1;
//opAssign ref (copy)
S s3;
s3 = s1;
//opAssign S (Move)
S func() {return S();}
s3 = func();
output:
this(this)
opAssign ref/copy
opAssign move
More information about the Digitalmars-d-learn
mailing list