Move semantics — transfer resources instead of copying.
1std::vector<int> a = {1, 2, 3};2std::vector<int> b = std::move(a); // a is now empty3// b = {1, 2, 3}
When to use std::move:
1// Returning local variables (NRVO may apply)2std::vector<int> create() {3 std::vector<int> v = {1, 2, 3};4 return v; // NRVO or move5}67// Transferring ownership8void consume(std::string s);9std::string name = "Alice";10consume(std::move(name)); // name is now in valid-but-unspecified state
Don't move:
const&