#include struct WrappedInt { int x; int id; }; int intID = 0; void ?{}( WrappedInt & this ) { this.id = intID++; sout | "constructing int id: " | this.id; this.x = 0; } void ?{}( WrappedInt & this, WrappedInt other ) { this.id = intID++; sout | "copy constructing int: " | other.x | "id: " | this.id; this.x = other.x; } void ?{}( WrappedInt & this, int x ) { this.id = intID++; sout | "constructing int: " | x | "id: " | this.id; this.x = x; } void ^?{}( WrappedInt & this ) { sout | "destructing int: " | this.x | "id: " | this.id; } /* WrappedInt */ void ?=?( WrappedInt & this, int x ) { sout | "assigning int: " | this.x | x | "id: " | this.id; this.x = x; // return this; } // WrappedInt ?=?( WrappedInt & this, WrappedInt other ) { // sout | "assigning int: " | this.x | other.x; // this.x = other.x; // return this; // } struct A { WrappedInt x, y, z; int id; }; int AID = 0; void ?{}( A & a ) { // currently must define default ctor, since there's no "= default" syntax a.id = AID++; sout | "default construct A" | a.id; } void ?{}( A & a, int x ) { a.id = AID++; sout | "begin construct A id: " | a.id; sout | "construct a.x"; (a.x){ x+999 }; sout | "assign a.y"; a.y = 0; // not a constructor - default constructor will be inserted sout | "end construct A"; } // z never constructed - will be automatically default constructed void ?{}( A & this, A other ) { this.id = AID++; sout | "begin copy construct A id: " | this.id; sout | "copy construct this.x"; (this.x){ other.x }; sout | "assign this.y"; this.y = other.y; // not a constructor - copy constructor will be inserted sout | "end copy construct A"; } // z never constructed - will be automatically copy constructed A ?=?( A & this, A other ) { sout | "begin ?=? A id: " | this.id; this.x = other.x; this.y = other.y; this.z = other.z; sout | "end ?=? A"; return this; } struct B { A a1, a2, a3; int id; }; int BID = 0; void ?{}( B & b ) { b.id = BID++; sout | "begin construct B id: " | b.id; sout | "assign b.a2"; b.a2 = (A){ 2 }; sout | "construct b.a1"; (b.a1){ 1 }; #ifdef ERR1 (b.a2){ b.a3 }; // error, b->a2 was used previously but is explicitly constructed #endif sout | "end construct B"; } // a2, a3 never constructed - will be automatically default constructed void ^?{}( B & b ) { b.id = BID++; sout | "begin destruct B id: " | b.id; b.a2 = (A) { 0 }; ^(b.a1){}; sout | "end destruct B"; } // a2, a3 never destructed - will be automatically destructed int main() { sout | "Before declaration of b1"; B b1; // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } } sout | "Before declaration of b2"; B b2 = b1; sout | "End of main"; }