1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_SWAP_RANGES_H
10#define _LIBCPP___ALGORITHM_SWAP_RANGES_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/specialized_algorithms.h>
14#include <__config>
15#include <__type_traits/enable_if.h>
16#include <__utility/move.h>
17#include <__utility/pair.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
26_LIBCPP_BEGIN_NAMESPACE_STD
27
28template <
29 class _AlgPolicy,
30 class _Iter1,
31 class _Sent1,
32 class _Iter2,
33 class _SpecialAlg =
34 __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >,
35 __enable_if_t<_SpecialAlg::__has_algorithm, int> = 0>
36_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
37 return _SpecialAlg()(std::move(__first1), std::move(__last1), std::move(__first2));
38}
39
40template <
41 class _AlgPolicy,
42 class _Iter1,
43 class _Sent1,
44 class _Iter2,
45 class _SpecialAlg =
46 __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >,
47 __enable_if_t<!_SpecialAlg::__has_algorithm, int> = 0>
48_LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
49 while (__first1 != __last1) {
50 _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
51 ++__first1;
52 ++__first2;
53 }
54
55 return pair<_Iter1, _Iter2>(std::move(__first1), std::move(__first2));
56}
57
58template <class _ForwardIterator1, class _ForwardIterator2>
59inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
60swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
61 return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second;
62}
63
64_LIBCPP_END_NAMESPACE_STD
65
66_LIBCPP_POP_MACROS
67
68#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H
69