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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
37__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
38 return _SpecialAlg()(std::move(__first1), std::move(__last1), std::move(__first2));
39}
40
41template <
42 class _AlgPolicy,
43 class _Iter1,
44 class _Sent1,
45 class _Iter2,
46 class _SpecialAlg =
47 __specialized_algorithm<_Algorithm::__swap_ranges, __iterator_pair<_Iter1, _Sent1>, __single_iterator<_Iter2> >,
48 __enable_if_t<!_SpecialAlg::__has_algorithm, int> = 0>
49_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2>
50__swap_ranges(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2) {
51 while (__first1 != __last1) {
52 _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
53 ++__first1;
54 ++__first2;
55 }
56
57 return pair<_Iter1, _Iter2>(std::move(__first1), std::move(__first2));
58}
59
60template <class _ForwardIterator1, class _ForwardIterator2>
61inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
62swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {
63 return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second;
64}
65
66_LIBCPP_END_NAMESPACE_STD
67
68_LIBCPP_POP_MACROS
69
70#endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H
71