Move semantics

Applies to: cpp

Move semantics transfers a resource (a vector's buffer, a unique_ptr's object) from one object to another instead of copying it, a big performance win for large temporaries. The compiler moves automatically when it can; std::move requests it explicitly.

std::vector<int> a = makeBig();   // moved out, not copied
std::vector<int> b = std::move(a); // a is now empty, b owns the buffer

See also: reference, smart-pointer