Skip to main content
Module 9 · Lesson 1 of 419/26 in the course~18 min
Module lessons (1/4)

Move Semantics, Rvalue (&&) and std::move

Lesson preview5 hands-on exercises readyCourse C++ · Module 9 — Move Semantics, Lambda and STL Modern

Lvalue vs rvalue, O(1) shift constructors/assignments, noexcept, and the 0/5 rule.

What you'll learn in this lesson

  • Distinguish lvalue (objects with a persistent name and address) from rvalue (temporary ready to be consumed).
  • Clear allocations and deep copies O(N) by writing move constructor and move assignment O(1) marked noexcept.
  • Apply the Rule of Zeros (preferring std::unique_ptr / std::vector) or Fives, including the valid-but-unspecified state after std::move.

Overview

Before C++11, returning a large std::vector or placing it in a collection risked duplicating every byte on the Heap. Move Semantics allow you to move the buffer pointer in just 3 CPU register assignments (O(1)), leaving the source empty and ready for destruction.

An lvalue has an in-memory identity and a name (int x = 5;); an rvalue is an unnamed ephemeral temporary value that is about to be destroyed (e.g. 42, "ciao", makeBuffer()). An rvalue reference (Buffer&&) hooks exclusively to these temporaries or objects converted with std::move:

Sections covered in this lesson

  1. 11. Lvalue vs Rvalue and T&&
  2. 22. Interactive Simulator: Deep Copy O(N) vs std::move O(1)
  3. 33. Implement Move Constructor & Move Assignment noexcept
  4. 44. Rule of Zero vs Rule of Five
  5. 5Practical exercises
  6. 6Check for understanding
Pro Lesson · Module 9 — Move Semantics, Lambda and STL Modern

Unlock "Move Semantics, Rvalue (&&) and std::move" and the full Course C++ curriculum

Lvalue vs rvalue, O(1) shift constructors/assignments, noexcept, and the 0/5 rule.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course C++ plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.