TRT
Sign in

Advanced · Module 10 · Lesson 1 of 6

Lvalues, Rvalues and Stealing Resources With Move

Move heap buffers instead of copying them, leave sources valid but empty, and make your vector and string moves non-throwing.

Pro — members onlyAbout 11 minutes

By the end you can

  • Distinguish lvalues from rvalues and explain what std::move does
  • Write a move constructor and move assignment that steal and null the source
  • Explain why moved-from objects must stay destructible

Builds on Function Templates: One max for Every Type.

01 · A question first

Returning a vector by value looks like it copies every element, yet it runs in constant time. A temporary string grows without duplicating its characters. What does the compiler know about temporaries that lets it steal instead of copy?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Why it is correct
  • What it costs
  • How to read a move in a review
  • A second move in action
  • A complete move example with MyString
  • Pitfalls and variations

03 · Practice

Something wrong with this lesson? Report a problem