l/r-value means the values left and right of the assignment operator= |
While that is the origin of the letters 'l' and 'r', that was only true in the long-extinct programming language CPL. It's grand-child C tried to redefine 'l' as 'locator' (that's how C standard explains the meaning of 'lvalue'), but that didn't stick.
if return std::move(s) returns an r-value, how can "def" be assigned to it ? |
It's not the return statement, it's the function call expression
bar()
that is an r-value of type
std::string
. Incidentally, the function call expression
foo()
is also an r-value of type
std::string
.
Strings, like most other classes, happen to allow assignment to rvalues.
Obviously, your code works but I have a hard time understanding how and deducts what the use case is for X&& goo() |
The use case was demonstrating that rvalue reference is a reference, with all that entails.