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 <__algorithm/equal.h>
13 #include <__algorithm/unwrap_range.h>
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>
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 # pragma GCC system_header
29 #if _LIBCPP_STD_VER >= 20
31 _LIBCPP_BEGIN_NAMESPACE_STD
36 template <input_iterator _Iter1
,
37 sentinel_for
<_Iter1
> _Sent1
,
38 input_iterator _Iter2
,
39 sentinel_for
<_Iter2
> _Sent2
,
40 class _Pred
= ranges::equal_to
,
41 class _Proj1
= identity
,
42 class _Proj2
= identity
>
43 requires indirectly_comparable
<_Iter1
, _Iter2
, _Pred
, _Proj1
, _Proj2
>
44 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
constexpr bool operator()(
51 _Proj2 __proj2
= {}) const {
52 if constexpr (sized_sentinel_for
<_Sent1
, _Iter1
> && sized_sentinel_for
<_Sent2
, _Iter2
>) {
53 if (__last1
- __first1
!= __last2
- __first2
)
56 auto __unwrapped1
= std::__unwrap_range(std::move(__first1
), std::move(__last1
));
57 auto __unwrapped2
= std::__unwrap_range(std::move(__first2
), std::move(__last2
));
58 return std::__equal_impl(
59 std::move(__unwrapped1
.first
),
60 std::move(__unwrapped1
.second
),
61 std::move(__unwrapped2
.first
),
62 std::move(__unwrapped2
.second
),
68 template <input_range _Range1
,
70 class _Pred
= ranges::equal_to
,
71 class _Proj1
= identity
,
72 class _Proj2
= identity
>
73 requires indirectly_comparable
<iterator_t
<_Range1
>, iterator_t
<_Range2
>, _Pred
, _Proj1
, _Proj2
>
74 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI
constexpr bool operator()(
75 _Range1
&& __range1
, _Range2
&& __range2
, _Pred __pred
= {}, _Proj1 __proj1
= {}, _Proj2 __proj2
= {}) const {
76 if constexpr (sized_range
<_Range1
> && sized_range
<_Range2
>) {
77 if (ranges::distance(__range1
) != ranges::distance(__range2
))
80 auto __unwrapped1
= std::__unwrap_range(ranges::begin(__range1
), ranges::end(__range1
));
81 auto __unwrapped2
= std::__unwrap_range(ranges::begin(__range2
), ranges::end(__range2
));
82 return std::__equal_impl(
83 std::move(__unwrapped1
.first
),
84 std::move(__unwrapped1
.second
),
85 std::move(__unwrapped2
.first
),
86 std::move(__unwrapped2
.second
),
93 } // namespace __equal
95 inline namespace __cpo
{
96 inline constexpr auto equal
= __equal::__fn
{};
100 _LIBCPP_END_NAMESPACE_STD
102 #endif // _LIBCPP_STD_VER >= 20
104 #endif // _LIBCPP___ALGORITHM_RANGES_EQUAL_H