1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_SWAP_RANGES_H
10 #define _LIBCPP___ALGORITHM_SWAP_RANGES_H
12 #include <__algorithm/iterator_operations.h>
14 #include <__utility/move.h>
15 #include <__utility/pair.h>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
21 _LIBCPP_BEGIN_NAMESPACE_STD
23 // 2+2 iterators: the shorter size will be used.
24 template <class _AlgPolicy
, class _ForwardIterator1
, class _Sentinel1
, class _ForwardIterator2
, class _Sentinel2
>
25 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
26 pair
<_ForwardIterator1
, _ForwardIterator2
>
27 __swap_ranges(_ForwardIterator1 __first1
, _Sentinel1 __last1
, _ForwardIterator2 __first2
, _Sentinel2 __last2
) {
28 while (__first1
!= __last1
&& __first2
!= __last2
) {
29 _IterOps
<_AlgPolicy
>::iter_swap(__first1
, __first2
);
34 return pair
<_ForwardIterator1
, _ForwardIterator2
>(std::move(__first1
), std::move(__first2
));
37 // 2+1 iterators: size2 >= size1.
38 template <class _AlgPolicy
, class _ForwardIterator1
, class _Sentinel1
, class _ForwardIterator2
>
39 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
40 pair
<_ForwardIterator1
, _ForwardIterator2
>
41 __swap_ranges(_ForwardIterator1 __first1
, _Sentinel1 __last1
, _ForwardIterator2 __first2
) {
42 while (__first1
!= __last1
) {
43 _IterOps
<_AlgPolicy
>::iter_swap(__first1
, __first2
);
48 return pair
<_ForwardIterator1
, _ForwardIterator2
>(std::move(__first1
), std::move(__first2
));
51 template <class _ForwardIterator1
, class _ForwardIterator2
>
52 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
53 swap_ranges(_ForwardIterator1 __first1
, _ForwardIterator1 __last1
, _ForwardIterator2 __first2
) {
54 return std::__swap_ranges
<_ClassicAlgPolicy
>(
55 std::move(__first1
), std::move(__last1
), std::move(__first2
)).second
;
58 _LIBCPP_END_NAMESPACE_STD
60 #endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H