As you might guess from the name, or you might have noticed in the preceding implementation, the std::copy algorithm works by copying elements from the input range to the output. As of C++11, you might wonder: What if instead of copying the elements, we used move semantics to move them from the input to the output?
The STL provides two different approaches to this problem. The first one is the most straightforward: there is a std::move algorithm (defined in the <algorithm> header) with the following definition:
template<class InIt, class OutIt>
OutIt move(InIt first1, InIt last1, OutIt destination)
{
while (first1 != last1) {
*destination = std::move(*first1);
++first1;
++destination;
}
return destination;
}
It's exactly the same as the std::copy algorithm...