vector partialsumconst vector arr vector resultarr size)result arr ]forint arr size)++ resulti resulti arri ]return resultvector vecvector sums partialsumvec )/copy in old ++move in ++ figure returning of stack-allocated rvalue in ++ in addition to the return-by-value and return-by-constant-reference idiomsfunctions can use return-by-reference this idiom is used in few places to allow the caller of function to have modifiable access to the internal data representation of class return-byreference in this context is discussed in section when we implement simple matrix class std::swap and std::move throughout this sectionwe have discussed instances in which ++ allows the programmer to easily replace expensive copies with moves yet another example of this is the implementation of swap routine swapping doubles is easily implemented with three copiesas shown in figure howeveralthough the same logic works to swap larger typesit comes with significant costnow the copies are very expensivehoweverit is easy to see that there is no need to copywhat we actually want is to do moves instead of copies in ++ if the right-hand side of the assignment operator (or constructoris an rvaluethen if the object supports movingwe can automatically avoid copies in other wordsif vector supports efficient movingand if at line were an rvaluethen could be moved into tmpsimilarlyif was an rvalue at line then it could be moved in to vector does indeed support movinghoweverxyand tmp are all lvalues at lines (rememberif an object has nameit is an lvaluefigure shows how this problem is solvedan implementation of swap at lines - shows that we can use cast to treat the right-hand side of lines - as rvalues the syntax of static cast is dauntingfortunatelyfunction std::move exists that converts any lvalue (or rvalueinto an rvalue note that the name is misleadingstd::move doesn' move anythingratherit makes value subject to be moved use of std::move is also shown in revised implementation of swap at lines - of figure the swap function std::swap is also part of the standard library and will work for any type