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
22 #include <__undef_macros>
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 // 2+2 iterators: the shorter size will be used.
27 template <class _AlgPolicy
, class _ForwardIterator1
, class _Sentinel1
, class _ForwardIterator2
, class _Sentinel2
>
28 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair
<_ForwardIterator1
, _ForwardIterator2
>
29 __swap_ranges(_ForwardIterator1 __first1
, _Sentinel1 __last1
, _ForwardIterator2 __first2
, _Sentinel2 __last2
) {
30 while (__first1
!= __last1
&& __first2
!= __last2
) {
31 _IterOps
<_AlgPolicy
>::iter_swap(__first1
, __first2
);
36 return pair
<_ForwardIterator1
, _ForwardIterator2
>(std::move(__first1
), std::move(__first2
));
39 // 2+1 iterators: size2 >= size1.
40 template <class _AlgPolicy
, class _ForwardIterator1
, class _Sentinel1
, class _ForwardIterator2
>
41 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair
<_ForwardIterator1
, _ForwardIterator2
>
42 __swap_ranges(_ForwardIterator1 __first1
, _Sentinel1 __last1
, _ForwardIterator2 __first2
) {
43 while (__first1
!= __last1
) {
44 _IterOps
<_AlgPolicy
>::iter_swap(__first1
, __first2
);
49 return pair
<_ForwardIterator1
, _ForwardIterator2
>(std::move(__first1
), std::move(__first2
));
52 template <class _ForwardIterator1
, class _ForwardIterator2
>
53 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator2
54 swap_ranges(_ForwardIterator1 __first1
, _ForwardIterator1 __last1
, _ForwardIterator2 __first2
) {
55 return std::__swap_ranges
<_ClassicAlgPolicy
>(std::move(__first1
), std::move(__last1
), std::move(__first2
)).second
;
58 _LIBCPP_END_NAMESPACE_STD
62 #endif // _LIBCPP___ALGORITHM_SWAP_RANGES_H