I am trying to come to terms with r-value references. I discovered that string's operator+ is always declared to return by value.
Why is operator+ defined to return by value:
basic_string operator+(basic_string&& lhs, const basic_string& rhs) {
return move( lhs.append(rhs) );
}
Why is it not defined like the following:
basic_string&& operator+(basic_string&& lhs, const basic_string& rhs) {
return move( lhs.append(rhs) );
}
Is this somehow invalid code?