Calling copyctor manually

SrMordred patric.dexheimer at gmail.com
Sat Jun 1 02:27:36 UTC 2019


Its possible to call copyctor manually without calling dtor?

ex, what i did before:

struct T{ ~this(){ writeln("DTOR"); } this(this){ 
writeln("POSTBLIT"); } }

T a;
T b;

memcpy(&a,&b,T.sizeof);
a.__postblit;

/*
output:
POSTBLIT
DTOR
DTOR
*/

With copy ctors, not sure what to do.


struct T{
~this(){ writeln("DTOR"); } 	
this(ref return scope T self){ writeln("COPYCTOR"); } }

T a;
T b;

memcpy(&a,&b,T.sizeof);
a.opAssign(b); //???
//same as a = b;

/*
output:
COPYCTOR
DTOR
DTOR
DTOR
*/

I want something like '.__xcopyctor'


More information about the Digitalmars-d-learn mailing list