[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __cxx03 / __algorithm / ranges_partition_copy.h
blob42cbb3a96a23755d86e30e34a5c9f7a2ea6b7a92
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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
10 #define _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
12 #include <__cxx03/__algorithm/in_out_out_result.h>
13 #include <__cxx03/__config>
14 #include <__cxx03/__functional/identity.h>
15 #include <__cxx03/__functional/invoke.h>
16 #include <__cxx03/__iterator/concepts.h>
17 #include <__cxx03/__iterator/iterator_traits.h>
18 #include <__cxx03/__iterator/projected.h>
19 #include <__cxx03/__ranges/access.h>
20 #include <__cxx03/__ranges/concepts.h>
21 #include <__cxx03/__ranges/dangling.h>
22 #include <__cxx03/__type_traits/remove_cvref.h>
23 #include <__cxx03/__utility/move.h>
25 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26 # pragma GCC system_header
27 #endif
29 _LIBCPP_PUSH_MACROS
30 #include <__cxx03/__undef_macros>
32 #if _LIBCPP_STD_VER >= 20
34 _LIBCPP_BEGIN_NAMESPACE_STD
36 namespace ranges {
38 template <class _InIter, class _OutIter1, class _OutIter2>
39 using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>;
41 namespace __partition_copy {
43 struct __fn {
44 // TODO(ranges): delegate to the classic algorithm.
45 template <class _InIter, class _Sent, class _OutIter1, class _OutIter2, class _Proj, class _Pred>
46 _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>,
47 __remove_cvref_t<_OutIter1>,
48 __remove_cvref_t<_OutIter2> >
49 __partition_copy_fn_impl(
50 _InIter&& __first,
51 _Sent&& __last,
52 _OutIter1&& __out_true,
53 _OutIter2&& __out_false,
54 _Pred& __pred,
55 _Proj& __proj) {
56 for (; __first != __last; ++__first) {
57 if (std::invoke(__pred, std::invoke(__proj, *__first))) {
58 *__out_true = *__first;
59 ++__out_true;
61 } else {
62 *__out_false = *__first;
63 ++__out_false;
67 return {std::move(__first), std::move(__out_true), std::move(__out_false)};
70 template <input_iterator _InIter,
71 sentinel_for<_InIter> _Sent,
72 weakly_incrementable _OutIter1,
73 weakly_incrementable _OutIter2,
74 class _Proj = identity,
75 indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
76 requires indirectly_copyable<_InIter, _OutIter1> && indirectly_copyable<_InIter, _OutIter2>
77 _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<_InIter, _OutIter1, _OutIter2> operator()(
78 _InIter __first, _Sent __last, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {})
79 const {
80 return __partition_copy_fn_impl(
81 std::move(__first), std::move(__last), std::move(__out_true), std::move(__out_false), __pred, __proj);
84 template <input_range _Range,
85 weakly_incrementable _OutIter1,
86 weakly_incrementable _OutIter2,
87 class _Proj = identity,
88 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
89 requires indirectly_copyable<iterator_t<_Range>, _OutIter1> && indirectly_copyable<iterator_t<_Range>, _OutIter2>
90 _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<borrowed_iterator_t<_Range>, _OutIter1, _OutIter2>
91 operator()(_Range&& __range, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) const {
92 return __partition_copy_fn_impl(
93 ranges::begin(__range), ranges::end(__range), std::move(__out_true), std::move(__out_false), __pred, __proj);
97 } // namespace __partition_copy
99 inline namespace __cpo {
100 inline constexpr auto partition_copy = __partition_copy::__fn{};
101 } // namespace __cpo
102 } // namespace ranges
104 _LIBCPP_END_NAMESPACE_STD
106 #endif // _LIBCPP_STD_VER >= 20
108 _LIBCPP_POP_MACROS
110 #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H