私はヒープ上のいくつかのデータを指すオブジェクトのmove construct/assign操作を実装しています。移動コンストラクタの強制テスト?
私はmove construct/assignとcopy construct/assignをテストしています。すべてがビルドされ、move構造を除くすべての作業がテストされています。 (移動割り当てが機能します)。
私はデバッガをトリップするように見えないので、移動コンストラクタのコードには到達していません。
私には何か簡単なものがありますか?
移動コンストラクタ...
//...
HeapBuffer (HeapBuffer&& other) // move
: data {other.data},
size {other.size}
{
assert(false); // hmm can't seem to debug to here in testing :(
other.data = nullptr;
other.size = 0;
}
//...
テスト機能...
ado::HeapBuffer<2048> makeHeapBuffer2048() // test move semantics
{
ado::HeapBuffer<2048> hb2048;
hb2048[777] = 123.0f;
return hb2048;
}
呼び出し元のテスト...
beginTest ("HeapBuffer move constructor"); // hmmm can't seem to get to the move constructor,
// strange because all the others work!?!?
{
ado::HeapBuffer<2048> hb {makeHeapBuffer2048()};
expectEquals (hb[777], 123.0f);
}
私が変更した場合、私はそれを追加します移動コンストラクタを使用して...
HeapBuffer (HeapBuffer&&) = delete;
...予想されたポイントでビルドが失敗します。テストによってトリップされた)。
エリジオンは、おそらく「C++コピーの省略」の – Jarod42
検索を発生する必要があります。 – nwp