File indexing completed on 2026-05-03 08:13:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
0010 #define _LIBCPP___ALGORITHM_RANGES_PARTITION_COPY_H
0011
0012 #include <__algorithm/in_out_out_result.h>
0013 #include <__config>
0014 #include <__functional/identity.h>
0015 #include <__functional/invoke.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/iterator_traits.h>
0018 #include <__iterator/projected.h>
0019 #include <__ranges/access.h>
0020 #include <__ranges/concepts.h>
0021 #include <__ranges/dangling.h>
0022 #include <__type_traits/remove_cvref.h>
0023 #include <__utility/move.h>
0024
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 # pragma GCC system_header
0027 #endif
0028
0029 _LIBCPP_PUSH_MACROS
0030 #include <__undef_macros>
0031
0032 #if _LIBCPP_STD_VER >= 20
0033
0034 _LIBCPP_BEGIN_NAMESPACE_STD
0035
0036 namespace ranges {
0037
0038 template <class _InIter, class _OutIter1, class _OutIter2>
0039 using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>;
0040
0041 struct __partition_copy {
0042
0043 template <class _InIter, class _Sent, class _OutIter1, class _OutIter2, class _Proj, class _Pred>
0044 _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>,
0045 __remove_cvref_t<_OutIter1>,
0046 __remove_cvref_t<_OutIter2> >
0047 __partition_copy_fn_impl(
0048 _InIter&& __first,
0049 _Sent&& __last,
0050 _OutIter1&& __out_true,
0051 _OutIter2&& __out_false,
0052 _Pred& __pred,
0053 _Proj& __proj) {
0054 for (; __first != __last; ++__first) {
0055 if (std::invoke(__pred, std::invoke(__proj, *__first))) {
0056 *__out_true = *__first;
0057 ++__out_true;
0058
0059 } else {
0060 *__out_false = *__first;
0061 ++__out_false;
0062 }
0063 }
0064
0065 return {std::move(__first), std::move(__out_true), std::move(__out_false)};
0066 }
0067
0068 template <input_iterator _InIter,
0069 sentinel_for<_InIter> _Sent,
0070 weakly_incrementable _OutIter1,
0071 weakly_incrementable _OutIter2,
0072 class _Proj = identity,
0073 indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
0074 requires indirectly_copyable<_InIter, _OutIter1> && indirectly_copyable<_InIter, _OutIter2>
0075 _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<_InIter, _OutIter1, _OutIter2> operator()(
0076 _InIter __first, _Sent __last, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {})
0077 const {
0078 return __partition_copy_fn_impl(
0079 std::move(__first), std::move(__last), std::move(__out_true), std::move(__out_false), __pred, __proj);
0080 }
0081
0082 template <input_range _Range,
0083 weakly_incrementable _OutIter1,
0084 weakly_incrementable _OutIter2,
0085 class _Proj = identity,
0086 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0087 requires indirectly_copyable<iterator_t<_Range>, _OutIter1> && indirectly_copyable<iterator_t<_Range>, _OutIter2>
0088 _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<borrowed_iterator_t<_Range>, _OutIter1, _OutIter2>
0089 operator()(_Range&& __range, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) const {
0090 return __partition_copy_fn_impl(
0091 ranges::begin(__range), ranges::end(__range), std::move(__out_true), std::move(__out_false), __pred, __proj);
0092 }
0093 };
0094
0095 inline namespace __cpo {
0096 inline constexpr auto partition_copy = __partition_copy{};
0097 }
0098 }
0099
0100 _LIBCPP_END_NAMESPACE_STD
0101
0102 #endif
0103
0104 _LIBCPP_POP_MACROS
0105
0106 #endif