std::move moves elements if possible, and copies otherwise. std::copy will always be copied.
libstdc ++ copy_move_a also accepts the _IsMove template _IsMove . These are the types of iterators, he delegates the template of the __copy_move class, which partially specializes for different categories of iterators, etc., But the most important thing: whether it is move or not. One of the specializations is
#if __cplusplus >= 201103L template<typename _Category> struct __copy_move<true, false, _Category> // first specialized template argument is whether to move { template<typename _II, typename _OI> static _OI __copy_m(_II __first, _II __last, _OI __result) { for (; __first != __last; ++__result, ++__first) *__result = std::move(*__first); // That may be your line return __result; } };
Your code cannot compile for a completely different reason: the second range is specified through move_iterator s. If you are looking for them, they return an rvalue reference to the object - and you cannot assign something the value x to a value of a scalar type.
int i; std::move(i) = 7;
std::move implicitly included in *__result and has the same category of values, that is, the value of x.
In your example
std::copy(std::make_move_iterator(s1.begin()), std::make_move_iterator(s1.end()), s2.begin());
should work fine.
source share