I’m learning about rvalue references, and the tutorial told me this:
X foo(); X x; x = foo();Rather obviously, it would be ok, and much more efficient, to swap resource pointers (handles) between x and the
temporary, and then let the temporary’s destructor destruct x’s original resource.In other words, in the special case where the right hand side of the
assignment is an rvalue, we want the copy assignment operator to act
like this.
So, does this mean that return values from functions are always constant by default, and thereby an rvalue? If yes: Are they always constant, or are there exceptions too?
Rvalue-ness and constant-ness are not synonyms, but rather a bit orthogonal. With the following definitions:
We can categorize the following expressions:
As of your particular question: no, not all rvalue expressions are constant.