Move Semantics

Right values, move constructors, std::move, and perfect forwarding.

Intermediate
Key Pointsstd::move is a cast that enables move; a moved-from object is valid but unspecified.
C++
#include <string>
#include <utility>
#include <vector>

std::vector<std::string> v;
std::string big(1'000'000, 'x');
v.push_back(big);              // copy: expensive
v.push_back(std::move(big));   // move: steals the buffer, O(1)
Follow the rule of five: if you define one of dtor/copy/move, define all five.

Friends & Partners