File indexing completed on 2025-12-16 10:27:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
0014 #define RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
0015
0016 #include <tuple>
0017
0018 #include <meta/meta.hpp>
0019
0020 #include <range/v3/range_fwd.hpp>
0021
0022 #include <range/v3/algorithm/result_types.hpp>
0023 #include <range/v3/functional/identity.hpp>
0024 #include <range/v3/functional/invoke.hpp>
0025 #include <range/v3/iterator/concepts.hpp>
0026 #include <range/v3/iterator/operations.hpp>
0027 #include <range/v3/iterator/traits.hpp>
0028 #include <range/v3/range/access.hpp>
0029 #include <range/v3/range/concepts.hpp>
0030 #include <range/v3/range/dangling.hpp>
0031 #include <range/v3/range/traits.hpp>
0032 #include <range/v3/utility/static_const.hpp>
0033
0034 #include <range/v3/detail/prologue.hpp>
0035
0036 namespace ranges
0037 {
0038
0039
0040 template<typename I, typename O0, typename O1>
0041 using partition_copy_result = detail::in_out1_out2_result<I, O0, O1>;
0042
0043 RANGES_FUNC_BEGIN(partition_copy)
0044
0045
0046 template(typename I,
0047 typename S,
0048 typename O0,
0049 typename O1,
0050 typename C,
0051 typename P = identity)(
0052 requires input_iterator<I> AND sentinel_for<S, I> AND
0053 weakly_incrementable<O0> AND weakly_incrementable<O1> AND
0054 indirectly_copyable<I, O0> AND indirectly_copyable<I, O1> AND
0055 indirect_unary_predicate<C, projected<I, P>>)
0056 constexpr partition_copy_result<I, O0, O1> RANGES_FUNC(partition_copy)(
0057 I first, S last, O0 o0, O1 o1, C pred, P proj = P{})
0058 {
0059 for(; first != last; ++first)
0060 {
0061 auto && x = *first;
0062 if(invoke(pred, invoke(proj, x)))
0063 {
0064 *o0 = (decltype(x) &&)x;
0065 ++o0;
0066 }
0067 else
0068 {
0069 *o1 = (decltype(x) &&)x;
0070 ++o1;
0071 }
0072 }
0073 return {first, o0, o1};
0074 }
0075
0076
0077 template(typename Rng,
0078 typename O0,
0079 typename O1,
0080 typename C,
0081 typename P = identity)(
0082 requires input_range<Rng> AND weakly_incrementable<O0> AND
0083 weakly_incrementable<O1> AND indirectly_copyable<iterator_t<Rng>, O0> AND
0084 indirectly_copyable<iterator_t<Rng>, O1> AND
0085 indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
0086 constexpr partition_copy_result<borrowed_iterator_t<Rng>, O0, O1>
0087 RANGES_FUNC(partition_copy)(Rng && rng, O0 o0, O1 o1, C pred, P proj = P{})
0088 {
0089 return (*this)(begin(rng),
0090 end(rng),
0091 std::move(o0),
0092 std::move(o1),
0093 std::move(pred),
0094 std::move(proj));
0095 }
0096
0097 RANGES_FUNC_END(partition_copy)
0098
0099 namespace cpp20
0100 {
0101 using ranges::partition_copy;
0102 using ranges::partition_copy_result;
0103 }
0104
0105 }
0106
0107 #include <range/v3/detail/epilogue.hpp>
0108
0109 #endif