rotate
rotate
template<class FwdIt>
void rotate(FwdIt first, FwdIt middle, FwdIt last);
The template function leaves the value originally stored in *(first + (N + (middle - last)) % (last - first))
subsequently stored in *(first + N)
for each N
in the range [0, last - first)
. Thus, if a ''left'' shift by one element leaves the element originally stored in *(first + (N + 1) % (last - first))
subsequently stored in *(first + N)
, then the function can be said to rotate the sequence either left by middle - first
elements or right by last - middle
elements. Both [first, middle)
and [middle, last)
must be valid ranges. The function swaps at most last - first
pairs of elements.
See the related sample program.