So, I understand what is s2associated with the expression s1 + s1, but is it evaluated at the point in time s2, or is it lazy and evaluated when called s2 += "Test";? Will it also s2store memory for the time line?
s2
s1 + s1
s2 += "Test";
#include <iostream> #include <string> int main() { std::string s1 = "Test"; std::string&& s2 = s1 + s1; s2 += "Test"; std::cout << s2 << '\n'; }
s2associated with an expression s1 + s1, but whether it is evaluated at the time it s2is assigned
Yes.
Will it also s2store memory for the time line?
Exactly s2attached to the temporary std::string.
std::string
s1 + s1 std::string, s2 ( ). s2 += "Test"; operator+=() s2, .. std::string.
operator+=()
, . ( ).
, , , , .
string operator+(...) pr-value ( rvalue). & &, .
string operator+(...)
, string& string::operator=(string&&) . , ++ 11 ( ++ 17 ) . copy/move elision (N) RVO, () .
string& string::operator=(string&&)