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_PARTITION_H
10 #define _LIBCPP___ALGORITHM_RANGES_PARTITION_H
12 #include <__cxx03/__algorithm/iterator_operations.h>
13 #include <__cxx03/__algorithm/make_projected.h>
14 #include <__cxx03/__algorithm/partition.h>
15 #include <__cxx03/__algorithm/ranges_iterator_concept.h>
16 #include <__cxx03/__config>
17 #include <__cxx03/__functional/identity.h>
18 #include <__cxx03/__functional/invoke.h>
19 #include <__cxx03/__functional/ranges_operations.h>
20 #include <__cxx03/__iterator/concepts.h>
21 #include <__cxx03/__iterator/iterator_traits.h>
22 #include <__cxx03/__iterator/permutable.h>
23 #include <__cxx03/__iterator/projected.h>
24 #include <__cxx03/__ranges/access.h>
25 #include <__cxx03/__ranges/concepts.h>
26 #include <__cxx03/__ranges/subrange.h>
27 #include <__cxx03/__utility/forward.h>
28 #include <__cxx03/__utility/move.h>
29 #include <__cxx03/__utility/pair.h>
31 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32 # pragma GCC system_header
36 #include <__cxx03/__undef_macros>
38 #if _LIBCPP_STD_VER >= 20
40 _LIBCPP_BEGIN_NAMESPACE_STD
43 namespace __partition
{
46 template <class _Iter
, class _Sent
, class _Proj
, class _Pred
>
47 _LIBCPP_HIDE_FROM_ABI
static constexpr subrange
<__remove_cvref_t
<_Iter
>>
48 __partition_fn_impl(_Iter
&& __first
, _Sent
&& __last
, _Pred
&& __pred
, _Proj
&& __proj
) {
49 auto&& __projected_pred
= std::__make_projected(__pred
, __proj
);
50 auto __result
= std::__partition
<_RangeAlgPolicy
>(
51 std::move(__first
), std::move(__last
), __projected_pred
, __iterator_concept
<_Iter
>());
53 return {std::move(__result
.first
), std::move(__result
.second
)};
56 template <permutable _Iter
,
57 sentinel_for
<_Iter
> _Sent
,
58 class _Proj
= identity
,
59 indirect_unary_predicate
<projected
<_Iter
, _Proj
>> _Pred
>
60 _LIBCPP_HIDE_FROM_ABI
constexpr subrange
<_Iter
>
61 operator()(_Iter __first
, _Sent __last
, _Pred __pred
, _Proj __proj
= {}) const {
62 return __partition_fn_impl(__first
, __last
, __pred
, __proj
);
65 template <forward_range _Range
,
66 class _Proj
= identity
,
67 indirect_unary_predicate
<projected
<iterator_t
<_Range
>, _Proj
>> _Pred
>
68 requires permutable
<iterator_t
<_Range
>>
69 _LIBCPP_HIDE_FROM_ABI
constexpr borrowed_subrange_t
<_Range
>
70 operator()(_Range
&& __range
, _Pred __pred
, _Proj __proj
= {}) const {
71 return __partition_fn_impl(ranges::begin(__range
), ranges::end(__range
), __pred
, __proj
);
75 } // namespace __partition
77 inline namespace __cpo
{
78 inline constexpr auto partition
= __partition::__fn
{};
82 _LIBCPP_END_NAMESPACE_STD
84 #endif // _LIBCPP_STD_VER >= 20
88 #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H