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 #if _LIBCPP_STD_VER >= 20 30 31 _LIBCPP_BEGIN_NAMESPACE_STD 32 33 namespace ranges { 34 namespace __equal { 35 struct __fn { 36 template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1, 37 input_iterator _Iter2, sentinel_for<_Iter2> _Sent2, 38 class _Pred = ranges::equal_to, 39 class _Proj1 = identity, 40 class _Proj2 = identity> 41 requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2> 42 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr operator__fn43 bool operator()(_Iter1 __first1, _Sent1 __last1, 44 _Iter2 __first2, _Sent2 __last2, 45 _Pred __pred = {}, 46 _Proj1 __proj1 = {}, 47 _Proj2 __proj2 = {}) const { 48 if constexpr (sized_sentinel_for<_Sent1, _Iter1> && sized_sentinel_for<_Sent2, _Iter2>) { 49 if (__last1 - __first1 != __last2 - __first2) 50 return false; 51 } 52 auto __unwrapped1 = std::__unwrap_range(std::move(__first1), std::move(__last1)); 53 auto __unwrapped2 = std::__unwrap_range(std::move(__first2), std::move(__last2)); 54 return std::__equal_impl(std::move(__unwrapped1.first), std::move(__unwrapped1.second), 55 std::move(__unwrapped2.first), std::move(__unwrapped2.second), 56 __pred, 57 __proj1, 58 __proj2); 59 } 60 61 template <input_range _Range1, 62 input_range _Range2, 63 class _Pred = ranges::equal_to, 64 class _Proj1 = identity, 65 class _Proj2 = identity> 66 requires indirectly_comparable<iterator_t<_Range1>, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> 67 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr operator__fn68 bool operator()(_Range1&& __range1, 69 _Range2&& __range2, 70 _Pred __pred = {}, 71 _Proj1 __proj1 = {}, 72 _Proj2 __proj2 = {}) const { 73 if constexpr (sized_range<_Range1> && sized_range<_Range2>) { 74 if (ranges::distance(__range1) != ranges::distance(__range2)) 75 return false; 76 } 77 auto __unwrapped1 = std::__unwrap_range(ranges::begin(__range1), ranges::end(__range1)); 78 auto __unwrapped2 = std::__unwrap_range(ranges::begin(__range2), ranges::end(__range2)); 79 return std::__equal_impl(std::move(__unwrapped1.first), std::move(__unwrapped1.second), 80 std::move(__unwrapped2.first), std::move(__unwrapped2.second), 81 __pred, 82 __proj1, 83 __proj2); 84 return false; 85 } 86 }; 87 } // namespace __equal 88 89 inline namespace __cpo { 90 inline constexpr auto equal = __equal::__fn{}; 91 } // namespace __cpo 92 } // namespace ranges 93 94 _LIBCPP_END_NAMESPACE_STD 95 96 #endif // _LIBCPP_STD_VER >= 20 97 98 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H 99