Move Semantics in C++

From the C++ cheat sheet · Smart Pointers & Move Semantics · verified Jul 2026

Move Semantics

Transfer resources instead of copying.

cpp
// Quick Reference
std::vector<int> a = {1, 2, 3};
std::vector<int> b = std::move(a);   // steal a's buffer, no copy
// a is now valid-but-unspecified (usually empty)
💡 Moving transfers ownership of internal resources (pointers/buffers) instead of deep-copying.
⚡ After std::move(x), x is valid but unspecified - only reassign or destroy it.
📌 std::move is just a cast to rvalue; the actual work happens in the move constructor.
🟢 Mark move operations noexcept so containers like std::vector can move (not copy) on resize.
move-semanticsrvalue

More C++ tasks

Back to the full C++ cheat sheet