25 Algorithms library [algorithms]

25.6 Mutating sequence operations [alg.modifying.operations]

25.6.11 Rotate [alg.rotate]

template<class ForwardIterator> constexpr ForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator rotate(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator middle, ForwardIterator last); template<permutable I, sentinel_for<I> S> constexpr subrange<I> ranges::rotate(I first, I middle, S last);
Requires: [first, middle) and [middle, last) shall be valid ranges.
For the overloads in namespace std, ForwardIterator shall meet the Cpp17ValueSwappable requirements ([swappable.requirements]), and the type of *first shall meet the Cpp17MoveConstructible (Table 26) and Cpp17MoveAssignable (Table 28) requirements.
Effects: For each non-negative integer i < (last - first), places the element from the position first + i into position first + (i + (last - middle)) % (last - first).
Note
:
This is a left rotate.
— end note
 ]
Returns:
  • first + (last - middle) for the overloads in namespace std, or
  • {first + (last - middle), last} for the overload in namespace ranges.
Complexity: At most last - first swaps.
template<forward_range R> requires permutable<iterator_t<R>> constexpr safe_subrange_t<R> ranges::rotate(R&& r, iterator_t<R> middle);
Effects: Equivalent to: return ranges​::​rotate(ranges​::​begin(r), middle, ranges​::​end(r));
template<class ForwardIterator, class OutputIterator> constexpr OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 rotate_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 middle, ForwardIterator1 last, ForwardIterator2 result); template<forward_iterator I, sentinel_for<I> S, weakly_incrementable O> requires indirectly_copyable<I, O> constexpr ranges::rotate_copy_result<I, O> ranges::rotate_copy(I first, I middle, S last, O result);
Let N be last - first.
Requires: [first, middle) and [middle, last) shall be valid ranges.
The ranges [first, last) and [result, result + N) shall not overlap.
Effects: Copies the range [first, last) to the range [result, result + N) such that for each non-negative integer the following assignment takes place: *(result + i) = *(first + (i + (middle - first)) % N).
Returns:
  • result + N for the overloads in namespace std, or
  • {last, result + N} for the overload in namespace ranges.
Complexity: Exactly N assignments.
template<forward_range R, weakly_incrementable O> requires indirectly_copyable<iterator_t<R>, O> constexpr ranges::rotate_copy_result<safe_iterator_t<R>, O> ranges::rotate_copy(R&& r, iterator_t<R> middle, O result);
Effects: Equivalent to:
return ranges::rotate_copy(ranges::begin(r), middle, ranges::end(r), result);