Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:20

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_PARTITION_COPY_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_PARTITION_COPY_H
0011 
0012 #include <__cxx03/__algorithm/in_out_out_result.h>
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__functional/identity.h>
0015 #include <__cxx03/__functional/invoke.h>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/iterator_traits.h>
0018 #include <__cxx03/__iterator/projected.h>
0019 #include <__cxx03/__ranges/access.h>
0020 #include <__cxx03/__ranges/concepts.h>
0021 #include <__cxx03/__ranges/dangling.h>
0022 #include <__cxx03/__type_traits/remove_cvref.h>
0023 #include <__cxx03/__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 <__cxx03/__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 namespace __partition_copy {
0042 
0043 struct __fn {
0044   // TODO(ranges): delegate to the classic algorithm.
0045   template <class _InIter, class _Sent, class _OutIter1, class _OutIter2, class _Proj, class _Pred>
0046   _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>,
0047                                                                __remove_cvref_t<_OutIter1>,
0048                                                                __remove_cvref_t<_OutIter2> >
0049   __partition_copy_fn_impl(
0050       _InIter&& __first,
0051       _Sent&& __last,
0052       _OutIter1&& __out_true,
0053       _OutIter2&& __out_false,
0054       _Pred& __pred,
0055       _Proj& __proj) {
0056     for (; __first != __last; ++__first) {
0057       if (std::invoke(__pred, std::invoke(__proj, *__first))) {
0058         *__out_true = *__first;
0059         ++__out_true;
0060 
0061       } else {
0062         *__out_false = *__first;
0063         ++__out_false;
0064       }
0065     }
0066 
0067     return {std::move(__first), std::move(__out_true), std::move(__out_false)};
0068   }
0069 
0070   template <input_iterator _InIter,
0071             sentinel_for<_InIter> _Sent,
0072             weakly_incrementable _OutIter1,
0073             weakly_incrementable _OutIter2,
0074             class _Proj = identity,
0075             indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
0076     requires indirectly_copyable<_InIter, _OutIter1> && indirectly_copyable<_InIter, _OutIter2>
0077   _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<_InIter, _OutIter1, _OutIter2> operator()(
0078       _InIter __first, _Sent __last, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {})
0079       const {
0080     return __partition_copy_fn_impl(
0081         std::move(__first), std::move(__last), std::move(__out_true), std::move(__out_false), __pred, __proj);
0082   }
0083 
0084   template <input_range _Range,
0085             weakly_incrementable _OutIter1,
0086             weakly_incrementable _OutIter2,
0087             class _Proj = identity,
0088             indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0089     requires indirectly_copyable<iterator_t<_Range>, _OutIter1> && indirectly_copyable<iterator_t<_Range>, _OutIter2>
0090   _LIBCPP_HIDE_FROM_ABI constexpr partition_copy_result<borrowed_iterator_t<_Range>, _OutIter1, _OutIter2>
0091   operator()(_Range&& __range, _OutIter1 __out_true, _OutIter2 __out_false, _Pred __pred, _Proj __proj = {}) const {
0092     return __partition_copy_fn_impl(
0093         ranges::begin(__range), ranges::end(__range), std::move(__out_true), std::move(__out_false), __pred, __proj);
0094   }
0095 };
0096 
0097 } // namespace __partition_copy
0098 
0099 inline namespace __cpo {
0100 inline constexpr auto partition_copy = __partition_copy::__fn{};
0101 } // namespace __cpo
0102 } // namespace ranges
0103 
0104 _LIBCPP_END_NAMESPACE_STD
0105 
0106 #endif // _LIBCPP_STD_VER >= 20
0107 
0108 _LIBCPP_POP_MACROS
0109 
0110 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_PARTITION_COPY_H