25 Algorithms library [algorithms]

25.6 Mutating sequence operations [alg.modifying.operations]

25.6.3 Swap [alg.swap]

template<class ForwardIterator1, class ForwardIterator2> constexpr ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 swap_ranges(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template<InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2> requires IndirectlySwappable<I1, I2> constexpr ranges::swap_ranges_result<I1, I2> ranges::swap_ranges(I1 first1, S1 last1, I2 first2, S2 last2); template<InputRange R1, InputRange R2> requires IndirectlySwappable<iterator_t<R1>, iterator_t<R2>> constexpr ranges::swap_ranges_result<safe_iterator_t<R1>, safe_iterator_t<R2>> ranges::swap_ranges(R1&& r1, R2&& r2);
Let:
  • last2 be first2 + (last1 - first1) for the overloads with no parameter named last2, and
  • M be .
Requires: The two ranges [first1, last1) and [first2, last2) shall not overlap.
For the overloads in namespace std, *(first1 + n) shall be swappable with ([swappable.requirements]) *(first2 + n).
Effects: For each non-negative integer performs:
  • swap(*(first1 + n), *(first2 + n)) for the overloads in namespace std, or
  • ranges::iter_­swap(first1 + n, first2 + n) for the overloads in namespace ranges.
Returns:
  • last2 for the overloads in namespace std, or
  • {first1 + M, first2 + M} for the overloads in namespace ranges.
Complexity: Exactly M swaps.
template<class ForwardIterator1, class ForwardIterator2> constexpr void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
Requires: a and b shall be dereferenceable.
*a shall be swappable with ([swappable.requirements]) *b.
Effects: As if by swap(*a, *b).