Share via


rotate_copy

rotate_copy

template<class FwdIt, class OutIt>
    OutIt rotate_copy(FwdIt first, FwdIt middle, FwdIt last, OutIt x);

The template function evaluates *(x + N) = *(first + (N + (middle - first)) % (last - first)) once 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 as it copies. Both [first, middle) and [middle, last) must be valid ranges.

If x and first designate regions of storage, the range [x, x + (last - first)) must not overlap the range [first, last).

See the related sample program.