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_RANGES_EQUAL_H
10 #define _LIBCPP___ALGORITHM_RANGES_EQUAL_H
12 #include <__cxx03/__algorithm/equal.h>
13 #include <__cxx03/__algorithm/unwrap_range.h>
14 #include <__cxx03/__config>
15 #include <__cxx03/__functional/identity.h>
16 #include <__cxx03/__functional/invoke.h>
17 #include <__cxx03/__functional/ranges_operations.h>
18 #include <__cxx03/__iterator/concepts.h>
19 #include <__cxx03/__iterator/distance.h>
20 #include <__cxx03/__iterator/indirectly_comparable.h>
21 #include <__cxx03/__ranges/access.h>
22 #include <__cxx03/__ranges/concepts.h>
23 #include <__cxx03/__utility/move.h>
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 # pragma GCC system_header
30 #include <__cxx03/__undef_macros>
32 #if _LIBCPP_STD_VER >= 20
34 _LIBCPP_BEGIN_NAMESPACE_STD
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 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr bool operator()(
54 _Proj2 __proj2
= {}) const {
55 if constexpr (sized_sentinel_for
<_Sent1
, _Iter1
> && sized_sentinel_for
<_Sent2
, _Iter2
>) {
56 if (__last1
- __first1
!= __last2
- __first2
)
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
),
71 template <input_range _Range1
,
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 [[nodiscard
]] _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
))
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
),
96 } // namespace __equal
98 inline namespace __cpo
{
99 inline constexpr auto equal
= __equal::__fn
{};
101 } // namespace ranges
103 _LIBCPP_END_NAMESPACE_STD
105 #endif // _LIBCPP_STD_VER >= 20
109 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H