25 Algorithms library [algorithms]

25.6 Mutating sequence operations [alg.modifying.operations]

25.6.10 Reverse [alg.reverse]

template<class BidirectionalIterator> constexpr void reverse(BidirectionalIterator first, BidirectionalIterator last); template<class ExecutionPolicy, class BidirectionalIterator> void reverse(ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last); template<BidirectionalIterator I, Sentinel<I> S> requires Permutable<I> constexpr I ranges::reverse(I first, S last); template<BidirectionalRange R> requires Permutable<iterator_t<R>> constexpr safe_iterator_t<R> ranges::reverse(R&& r);
Requires: For the overloads in namespace std, BidirectionalIterator shall meet the Cpp17ValueSwappable requirements ([swappable.requirements]).
Effects: For each non-negative integer i < (last - first) / 2, applies std::iter_­swap, or ranges::​iter_­swap for the overloads in namespace ranges, to all pairs of iterators first + i, (last - i) - 1.
Returns: last for the overloads in namespace ranges.
Complexity: Exactly (last - first)/2 swaps.
template<class BidirectionalIterator, class OutputIterator> constexpr OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); template<class ExecutionPolicy, class BidirectionalIterator, class ForwardIterator> ForwardIterator reverse_copy(ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last, ForwardIterator result); template<BidirectionalIterator I, Sentinel<I> S, WeaklyIncrementable O> requires IndirectlyCopyable<I, O> constexpr ranges::reverse_copy_result<I, O> ranges::reverse_copy(I first, S last, O result); template<BidirectionalRange R, WeaklyIncrementable O> requires IndirectlyCopyable<iterator_t<R>, O> constexpr ranges::reverse_copy_result<safe_iterator_t<R>, O> ranges::reverse_copy(R&& r, O result);
Let N be last - first.
Requires: 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 every non-negative integer i < N the following assignment takes place: *(result + N - 1 - i) = *(first + i).
  • result + N for the overloads in namespace std, or
  • {last, result + N} for the overloads in namespace ranges.
Complexity: Exactly N assignments.