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_IS_PERMUTATION_H
10 #define _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H
12 #include <__cxx03/__algorithm/is_permutation.h>
13 #include <__cxx03/__algorithm/iterator_operations.h>
14 #include <__cxx03/__config>
15 #include <__cxx03/__functional/identity.h>
16 #include <__cxx03/__functional/ranges_operations.h>
17 #include <__cxx03/__iterator/concepts.h>
18 #include <__cxx03/__iterator/distance.h>
19 #include <__cxx03/__iterator/projected.h>
20 #include <__cxx03/__ranges/access.h>
21 #include <__cxx03/__ranges/concepts.h>
22 #include <__cxx03/__utility/move.h>
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 # pragma GCC system_header
29 #include <__cxx03/__undef_macros>
31 #if _LIBCPP_STD_VER >= 20
33 _LIBCPP_BEGIN_NAMESPACE_STD
36 namespace __is_permutation
{
38 template <class _Iter1
, class _Sent1
, class _Iter2
, class _Sent2
, class _Proj1
, class _Proj2
, class _Pred
>
39 _LIBCPP_HIDE_FROM_ABI
constexpr static bool __is_permutation_func_impl(
47 return std::__is_permutation
<_RangeAlgPolicy
>(
48 std::move(__first1
), std::move(__last1
), std::move(__first2
), std::move(__last2
), __pred
, __proj1
, __proj2
);
52 forward_iterator _Iter1
,
53 sentinel_for
<_Iter1
> _Sent1
,
54 forward_iterator _Iter2
,
55 sentinel_for
<_Iter2
> _Sent2
,
56 class _Proj1
= identity
,
57 class _Proj2
= identity
,
58 indirect_equivalence_relation
<projected
<_Iter1
, _Proj1
>, projected
<_Iter2
, _Proj2
>> _Pred
= ranges::equal_to
>
59 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr bool operator()(
66 _Proj2 __proj2
= {}) const {
67 return __is_permutation_func_impl(
68 std::move(__first1
), std::move(__last1
), std::move(__first2
), std::move(__last2
), __pred
, __proj1
, __proj2
);
71 template <forward_range _Range1
,
72 forward_range _Range2
,
73 class _Proj1
= identity
,
74 class _Proj2
= identity
,
75 indirect_equivalence_relation
<projected
<iterator_t
<_Range1
>, _Proj1
>,
76 projected
<iterator_t
<_Range2
>, _Proj2
>> _Pred
= ranges::equal_to
>
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
))
84 return __is_permutation_func_impl(
85 ranges::begin(__range1
),
86 ranges::end(__range1
),
87 ranges::begin(__range2
),
88 ranges::end(__range2
),
94 } // namespace __is_permutation
96 inline namespace __cpo
{
97 inline constexpr auto is_permutation
= __is_permutation::__fn
{};
101 _LIBCPP_END_NAMESPACE_STD
103 #endif // _LIBCPP_STD_VER >= 20
107 #endif // _LIBCPP___ALGORITHM_RANGES_IS_PERMUTATION_H