8.5 KiB
[alg.shift]
26 Algorithms library [algorithms]
26.7 Mutating sequence operations [alg.modifying.operations]
26.7.14 Shift [alg.shift]
`template constexpr ForwardIterator shift_left(ForwardIterator first, ForwardIterator last, typename iterator_traits::difference_type n); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator shift_left(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, typename iterator_traits::difference_type n);
template<permutable I, sentinel_for S> constexpr subrange ranges::shift_left(I first, S last, iter_difference_t n); template<forward_range R> requires permutable<iterator_t> constexpr borrowed_subrange_t ranges::shift_left(R&& r, range_difference_t n);
template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S> requires permutable subrange ranges::shift_left(Ep&& exec, I first, S last, iter_difference_t n); template<execution-policy Ep, sized-random-access-range R> requires permutable<iterator_t> borrowed_subrange_t ranges::shift_left(Ep&& exec, R&& r, range_difference_t n); `
Preconditions: n >= 0 is true.
For the overloads in namespace std, the type of *first meets the Cpp17MoveAssignable requirements.
Effects: If n == 0 or n >= last - first, does nothing.
Otherwise, moves the element from position first + n + i into position first + i for each non-negative integer i < (last - first) - n.
For the non-parallel algorithm overloads, does so in order starting from i = 0 and proceeding to i = (last - first) - n - 1.
Returns: Let NEW_LAST be first + (last - first - n) if n < last - first, otherwise first.
Returns:
-
NEW_LAST for the overloads in namespace std.
-
{first, NEW_LAST} for the overloads in namespace ranges.
Complexity: At most (last - first) - n assignments.
`template constexpr ForwardIterator shift_right(ForwardIterator first, ForwardIterator last, typename iterator_traits::difference_type n); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator shift_right(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, typename iterator_traits::difference_type n);
template<permutable I, sentinel_for S> constexpr subrange ranges::shift_right(I first, S last, iter_difference_t n); template<forward_range R> requires permutable<iterator_t> constexpr borrowed_subrange_t ranges::shift_right(R&& r, range_difference_t n);
template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S> requires permutable subrange ranges::shift_right(Ep&& exec, I first, S last, iter_difference_t n); template<execution-policy Ep, sized-random-access-range R> requires permutable<iterator_t> borrowed_subrange_t ranges::shift_right(Ep&& exec, R&& r, range_difference_t n); `
Preconditions: n >= 0 is true.
For the overloads in namespace std, the type of *first meets the Cpp17MoveAssignable requirements, and ForwardIterator meets the Cpp17BidirectionalIterator requirements ([bidirectional.iterators]) or the Cpp17ValueSwappable requirements.
Effects: If n == 0 or n >= last - first, does nothing.
Otherwise, moves the element from position first + i into position first + n + i for each non-negative integer i < (last - first) - n.
Does so in order starting from i = (last - first) - n - 1 and proceeding to i = 0 if
for the non-parallel algorithm overload in namespace std,ForwardIterator meets the Cpp17BidirectionalIterator requirements,
for the non-parallel algorithm overloads in namespace ranges,I models bidirectional_iterator.
Returns: Let NEW_FIRST be first + n if n < last - first, otherwise last.
Returns:
-
NEW_FIRST for the overloads in namespace std.
-
{NEW_FIRST, last} for the overloads in namespace ranges.
Complexity: At most (last - first) - n assignments or swaps.