You have labelled the lines incorrectly. Neither of them are assignments, let alone copy and move assignments respectively. Instead, the first involves copy/move construction (depending on if X
has a move constructor) and the second is simply initialising a reference.
The preferred way to receive the return value of a function call is the first way:
X a = f();
The copy from the temporary returned by f()
into the object a
will almost certainly be elided. This is the same form that auto c = f();
will take.
The second one should rarely, if ever, appear in your code. You are making an rvalue reference to the return type of f()
. Stroustrup is only doing this to demonstrate that temporaries can bind to rvalue references. This occurs most often in real code when you invoke a move constructor/assignment operator, which have an rvalue reference argument type.