string ident(string arg) // string passed by value (copied into arg)
{
return arg; // return string (move the value of arg out of ident() to a caller)
}
int main ()
{
string s1 {"Adams"}; // initialize string (construct in s1).
s1 = idet(s1); // copy s1 into ident()
// move the result of ident(s1) into s1;
// s1's value is "Adams".
string s2 {"Pratchett"}; // initialize string (construct in s2)
s1 = s2; // copy the value of s2 into s1
// both s1 and s2 have the value "Pratchett".
}
Several functions are used here:
• A constructor initializing a string with a string literal (used for s1 and s2)
• A copy constructor copying a string (into the function argument arg)
• A move constructor moving the value of a string (from arg out of ident() into a temporary variable holding the result of ident(s1))
• A move assignment moving the value of a string (from the temporary variable holding the result of ident(s1) into s1)
• A copy assignment copying a string (from s2 into s1)
• A destructor releasing the resources owned by s1, s2, and the temporary variable holding the result of ident(s1), and doing nothing to the moved-from function argument
An optimizer can eliminate some of this work. For example, in this simple example the temporary variable is typically eliminated. However, in principle, these operations are executed.
The above is from C++ programming language book.
My question is because temporary variable holding the result of ident(s1) and function argument and both moved from objects. Why the author said A destructor releasing the resources owned by temporary variable but do nothing with the function argument?