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_ITERATOR_OPERATIONS_H 10 #define _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H 11 12 #include <__algorithm/iter_swap.h> 13 #include <__config> 14 #include <__iterator/advance.h> 15 #include <__iterator/distance.h> 16 #include <__iterator/iter_move.h> 17 #include <__iterator/iter_swap.h> 18 #include <__iterator/iterator_traits.h> 19 #include <__iterator/next.h> 20 #include <__utility/forward.h> 21 #include <__utility/move.h> 22 #include <type_traits> 23 24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 25 # pragma GCC system_header 26 #endif 27 28 _LIBCPP_BEGIN_NAMESPACE_STD 29 30 template <class _AlgPolicy> struct _IterOps; 31 32 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 33 struct _RangeAlgPolicy {}; 34 35 template <> 36 struct _IterOps<_RangeAlgPolicy> { 37 static constexpr auto advance = ranges::advance; 38 static constexpr auto distance = ranges::distance; 39 static constexpr auto __iter_move = ranges::iter_move; 40 static constexpr auto iter_swap = ranges::iter_swap; 41 static constexpr auto next = ranges::next; 42 static constexpr auto __advance_to = ranges::advance; 43 }; 44 #endif 45 46 struct _ClassicAlgPolicy {}; 47 48 template <> 49 struct _IterOps<_ClassicAlgPolicy> { 50 51 // advance 52 template <class _Iter, class _Distance> 53 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 54 static void advance(_Iter& __iter, _Distance __count) { 55 std::advance(__iter, __count); 56 } 57 58 // distance 59 template <class _Iter> 60 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 61 static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last) { 62 return std::distance(__first, __last); 63 } 64 65 // iter_move 66 template <class _Iter> 67 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 68 // Declaring the return type is necessary for the C++03 mode (which doesn't support placeholder return types). 69 static typename iterator_traits<__uncvref_t<_Iter> >::value_type&& __iter_move(_Iter&& __i) { 70 return std::move(*std::forward<_Iter>(__i)); 71 } 72 73 // iter_swap 74 template <class _Iter1, class _Iter2> 75 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 76 static void iter_swap(_Iter1&& __a, _Iter2&& __b) { 77 std::iter_swap(std::forward<_Iter1>(__a), std::forward<_Iter2>(__b)); 78 } 79 80 // next 81 template <class _Iterator> 82 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 83 _Iterator next(_Iterator, _Iterator __last) { 84 return __last; 85 } 86 87 template <class _Iter> 88 _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_AFTER_CXX11 void __advance_to(_Iter& __first, _Iter __last) { 89 __first = __last; 90 } 91 }; 92 93 _LIBCPP_END_NAMESPACE_STD 94 95 #endif // _LIBCPP___ALGORITHM_ITERATOR_OPERATIONS_H 96