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_RANGES_EQUAL_H 10 #define _LIBCPP___ALGORITHM_RANGES_EQUAL_H 11 12 #include <__algorithm/equal.h> 13 #include <__algorithm/unwrap_range.h> 14 #include <__config> 15 #include <__functional/identity.h> 16 #include <__functional/invoke.h> 17 #include <__functional/ranges_operations.h> 18 #include <__iterator/concepts.h> 19 #include <__iterator/distance.h> 20 #include <__iterator/indirectly_comparable.h> 21 #include <__ranges/access.h> 22 #include <__ranges/concepts.h> 23 #include <__utility/move.h> 24 25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 26 # pragma GCC system_header 27 #endif 28 29 _LIBCPP_PUSH_MACROS 30 #include <__undef_macros> 31 32 #if _LIBCPP_STD_VER >= 20 33 34 _LIBCPP_BEGIN_NAMESPACE_STD 35 36 namespace ranges { 37 namespace __equal { 38 struct __fn { 39 template <input_iterator _Iter1, 40 sentinel_for<_Iter1> _Sent1, 41 input_iterator _Iter2, 42 sentinel_for<_Iter2> _Sent2, 43 class _Pred = ranges::equal_to, 44 class _Proj1 = identity, 45 class _Proj2 = identity> 46 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> 47 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( 48 _Iter1 __first1, 49 _Sent1 __last1, 50 _Iter2 __first2, 51 _Sent2 __last2, 52 _Pred __pred = {}, 53 _Proj1 __proj1 = {}, 54 _Proj2 __proj2 = {}) const { 55 if constexpr (sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>) { 56 if (__last1 - __first1 != __last2 - __first2) 57 return false; 58 } 59 auto __unwrapped1 = std::__unwrap_range(std::move(__first1), std::move(__last1)); 60 auto __unwrapped2 = std::__unwrap_range(std::move(__first2), std::move(__last2)); 61 return std::__equal_impl( 62 std::move(__unwrapped1.first), 63 std::move(__unwrapped1.second), 64 std::move(__unwrapped2.first), 65 std::move(__unwrapped2.second), 66 __pred, 67 __proj1, 68 __proj2); 69 } 70 71 template <input_range _Range1, 72 input_range _Range2, 73 class _Pred = ranges::equal_to, 74 class _Proj1 = identity, 75 class _Proj2 = identity> 76 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> 77 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( 78 _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { 79 if constexpr (sized_range<_Range1> && sized_range<_Range2>) { 80 if (ranges::distance(__range1) != ranges::distance(__range2)) 81 return false; 82 } 83 auto __unwrapped1 = std::__unwrap_range(ranges::begin(__range1), ranges::end(__range1)); 84 auto __unwrapped2 = std::__unwrap_range(ranges::begin(__range2), ranges::end(__range2)); 85 return std::__equal_impl( 86 std::move(__unwrapped1.first), 87 std::move(__unwrapped1.second), 88 std::move(__unwrapped2.first), 89 std::move(__unwrapped2.second), 90 __pred, 91 __proj1, 92 __proj2); 93 return false; 94 } 95 }; 96 } // namespace __equal 97 98 inline namespace __cpo { 99 inline constexpr auto equal = __equal::__fn{}; 100 } // namespace __cpo 101 } // namespace ranges 102 103 _LIBCPP_END_NAMESPACE_STD 104 105 #endif // _LIBCPP_STD_VER >= 20 106 107 _LIBCPP_POP_MACROS 108 109 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H 110