ムーブコンストラクタを使用して、ほとんどすべてのクラスのムーブ代入を定義する非常に簡単な方法は次のとおりです。
class Foo {
public:
Foo(Foo&& foo); // you still have to write this one
Foo& operator=(Foo&& foo) {
if (this != &foo) { // avoid destructing the only copy
this->~Foo(); // call your own destructor
new (this) Foo(std::move(foo)); // call move constructor via placement new
}
return *this;
}
// ...
};
独自のデストラクタを呼び出してから、このポインタに新しい配置を行うというこのシーケンスは、標準のC ++ 11で安全ですか?