Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Qt and Trivial Relocation (Part 4)

On trivial relocation and move assignments

Same problem: how to erase B from the vector?

First steps: B gets destroyed; C is move-constructed over it.

Destroy the moved-from C object, move-construct D over it

Destroy moved-from D. It's the last element, nothing else to move around. Update bookkeeping and we're done.

int a = 1;
int b = 2;

using T = std::tuple<int &>;
T ta(a);
T tb(b); 

#if USE_MOVE_ASSIGN
// move-assignment from tb
ta = std::move(tb);          // a = 2, b = 2
#else
// destroy ta + move-construct from tb
ta.~T();
new (&ta) T(std::move(tb));  // a = 1, b = 2
#endif

About KDAB


GiuseppeD'Angelo

Giuseppe D’Angelo

Senior Software Engineer

Learn Modern C++

Learn more