63 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H10#define _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H11 12#include <__cxx03/__algorithm/iterator_operations.h>13#include <__cxx03/__config>14#include <__cxx03/__utility/move.h>15#include <__cxx03/__utility/pair.h>16 17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif20 21_LIBCPP_PUSH_MACROS22#include <__cxx03/__undef_macros>23 24_LIBCPP_BEGIN_NAMESPACE_STD25 26// 2+2 iterators: the shorter size will be used.27template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>28_LIBCPP_HIDE_FROM_ABI 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);32 ++__first1;33 ++__first2;34 }35 36 return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2));37}38 39// 2+1 iterators: size2 >= size1.40template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2>41_LIBCPP_HIDE_FROM_ABI pair<_ForwardIterator1, _ForwardIterator2>42__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2) {43 while (__first1 != __last1) {44 _IterOps<_AlgPolicy>::iter_swap(__first1, __first2);45 ++__first1;46 ++__first2;47 }48 49 return pair<_ForwardIterator1, _ForwardIterator2>(std::move(__first1), std::move(__first2));50}51 52template <class _ForwardIterator1, class _ForwardIterator2>53inline _LIBCPP_HIDE_FROM_ABI _ForwardIterator254swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) {55 return std::__swap_ranges<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2)).second;56}57 58_LIBCPP_END_NAMESPACE_STD59 60_LIBCPP_POP_MACROS61 62#endif // _LIBCPP___CXX03___ALGORITHM_SWAP_RANGES_H63