1 static struct Foo 2 { 3 pure nothrow @nogc: 4 this(int* ptr) { _ptr = ptr; } 5 ~this() { if (_ptr) ++*_ptr; } 6 int* _ptr; 7 } 8 9 int val; 10 Foo foo1 = void; // uninitialized 11 auto foo2 = Foo(&val); // initialized 12 assert(foo2._ptr is &val); 13 14 // Using `move(foo2, foo1)` would have an undefined effect because it would destroy 15 // the uninitialized foo1. 16 // moveEmplace directly overwrites foo1 without destroying or initializing it first. 17 moveEmplace(foo2, foo1); 18 assert(foo1._ptr is &val); 19 assert(foo2._ptr is null); 20 assert(val == 0);
Similar to move but assumes target is uninitialized. This is more efficient because source can be blitted over target without destroying or initializing it first.