I am new to c++11 and have the following question while reading the C++11 FAQ.
Suppose we have a function f
() that returns a value in type X
, then we have the following ways to store its returned value:
X a = f(); // copy assignment
X&& b = f(); // move assignment
According to C++ FAQ, the second one avoids an unnecessary copy.
My question is: is the second one always the preferred way to receive the return value of a function call? In addition, is auto c = f();
equivalent to one of the above assignments? Thank you.