liveBook · Manning

Rvalue

As explained in Learn C++ by Example

An rvalue is an expression category representing a value that is generally suitable for moving or binding to an rvalue reference.

An rvalue is an expression category for a value that is usually temporary and suitable for moving. Unlike a named lvalue, it has no lasting name; using it can avoid copying data. section 2.2.3

Recognize rvalues through their role in container operations:

  • A literal such as 42 is an rvalue, while a named variable such as x is an lvalue. section 2.2.3
  • A temporary vector returned by get_next_row can bind to push_back(T&&) and be moved instead of copied. section 2.2.3
  • emplace_back can construct the container element directly from the temporary. section 2.2.3

Moving temporary triangle rows

generate_triangle builds each row with get_next_row(triangle.back()) and passes that temporary directly to triangle.push_back, avoiding a separate copy. section 2.2.3

Figure 2.4 A move-constructed vector can steal the rvalue’s elements.
CH02_F04_Buontempo

A move-constructed vector can take ownership of an rvalue's elements rather than duplicating them. section 2.2.3

How Learn C++ by Example covers it

How deep it goes
Defines rvalues through lvalue contrast, then explains references, move construction, and emplacement; defers full value-category details.
Examples
Demonstrates temporary vectors in triangle generation, push_back overloads, move construction, and vector storage diagrams.
What it assumes
Builds from named variables and literals, then introduces temporary vectors without requiring full value-category coverage.
What you can do after
Apply rvalues through push_back, emplace_back, and std::move to avoid copying temporary objects.
How it connects
Connects rvalues with lvalues, rvalue references, move semantics, move constructors, perfect forwarding, push_back, emplace_back, and std::move.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.