Is there any way how to use std::rotate
for the list
std::list<int> v = { 0,7, 1,2 };
since these left/right rotations
std::rotate(v.begin(), v.begin() + 1, v.end());
std::rotate(v.rbegin(), v.rbegin() + 1, v.rend());
work for the vector?
std::vector<int> v = { 0, 7, 1, 2 };
One possible way is to copy the list to the vector
std::vector<int> u{ std::begin(v), std::end(v) };
and vice versa but I found it too "lengthy"... A direct rotation of the list leads to the following errors:
Error C2672 'std::rotate': no matching overloaded function found
Error C2676 binary '+': std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>' does not define this operator or a conversion to a type acceptable to the predefined operator
Thanks for your help.
std::list
has BidirectionalIterator. They don't implementoperator+
. You have to iterate to the point you want to have as new first... coliru.stacked-crooked.com/a/633363afbc94a64aoperator+
overload for your needs; quick and dirty.