This is a bit theoretical question, but although I have some basic understanding of the std::move Im still not certain if it provides some additional functionality to the la
Doing this the way you suggest is a lot more complicated than necessary:
std::string s1="STL";
std::string s2(s1);
std::cout << s1 <
In this case, it is fairly sure that a copy is meant. But if you drop the last line, s1
essentially ends its lifetime after the construction of s2
.
In a reference counted implementation, the copy constructor for std::string
will only increment the reference counter, while the destructor will decrement and delete if it becomes zero.
So the sequence is
std::string::string(char const *)
)
std::string::string(std::string const &)
)
Now the compiler can flatten that, simply initialize the reference counter to 2 and store the pointer twice. Common Subexpression Elimination then finds out that s1
and s2
keep the same pointer value, and merges them into one.
In short, the only difference in generated code should be that the reference counter is initialized to 2.