Rvalue references are a feature of C++ that was added with the C++11 standard. What makes
rvalue references a bit difficult to grasp is that when you first look at them, it is not clear what
their purpose is or what problems they solve. Therefore, I will not jump right in and explain
what rvalue references are. Instead, I will start with the problems that are to be solved and
then show how rvalue references provide the solution. That way, the definition of rvalue
references will appear plausible and natural to you.
Rvalue references solve at least two problems:
Implementing move semantics
If you are not familiar with these problems, do not worry. Both of them will be explained in
detail below. We'll start with move semantics. But before we're ready to go, I need to remind
you of what lvalues and rvalues are in C++. Giving a rigorous definition is surprisingly difficult,
but the explanation below is good enough for the purpose at hand.
The original definition of lvalues and rvalues from the earliest days of C is as follows: An
is an expression
that may appear on the left or on the right hand side of an assignment,
is an expression that can only appear on the right hand side of an