Rvalue References and the && Syntax
Bind to temporaries with rvalue references for efficient resource transfer.
The && Syntax
An rvalue reference is declared with T&&. It binds only to rvalues — temporaries about to die.
int&& ref = 42; // OK: binds to literal
int x = 10;
// int&& bad = x; // ERROR: x is an lvalueWhy Have rvalue References?
They let you write functions that know the argument is about to be destroyed. You can take its resources without making a copy.
All lessons in this course
- Lvalue vs Rvalue The Distinction
- Rvalue References and the && Syntax
- std::move and std::forward
- Move Constructors and Move Assignment