I've been reading about (N)RVO and would like one, complete scenario description. I hope this question will serve other C++ -learners to clarify their ideas.
Suppose this scenario:
string get_string() {
string x("racecar");
//work on x...
return x;
}
string a( get_string() );
string b = get_string();
Please disregard the C++11 move-semantics for a moment.
- If no (N)RVO is performed, how many constructors/assignments/destructors will be
executed? (please point out, to which objects to they refer)
- What changes if (N)RVO is applied?
- Finally, how does the situation change in C++11 assuming, that
std::string
supports move-semantics.