I am looking at code from Microsoft and I noticed the following:
An optional parameter std::vector<T>* vOut
is passed into a function.
The function itself uses a separate local std::vector<T> result
for the optional result.
At the end of the function, they do the following to pass the result to the caller:
if(vOut) {
std::swap(*vOut,result);
}
why would someone use a std::swap
here instead of a move-assignment like
*vOut = std::move(result)
?
Here is an example