Horizon
Loading...
Searching...
No Matches
partition_copy.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2014-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13#ifndef RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
14#define RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
15
16#include <tuple>
17
18#include <meta/meta.hpp>
19
21
22#include <range/v3/algorithm/result_types.hpp>
32#include <range/v3/utility/static_const.hpp>
33
34#include <range/v3/detail/prologue.hpp>
35
36namespace ranges
37{
40 template<typename I, typename O0, typename O1>
41 using partition_copy_result = detail::in_out1_out2_result<I, O0, O1>;
42
43 RANGES_FUNC_BEGIN(partition_copy)
44
45
46 template(typename I,
47 typename S,
48 typename O0,
49 typename O1,
50 typename C,
51 typename P = identity)(
52 requires input_iterator<I> AND sentinel_for<S, I> AND
54 indirectly_copyable<I, O0> AND indirectly_copyable<I, O1> AND
55 indirect_unary_predicate<C, projected<I, P>>)
56 constexpr partition_copy_result<I, O0, O1> RANGES_FUNC(partition_copy)(
57 I first, S last, O0 o0, O1 o1, C pred, P proj = P{})
58 {
59 for(; first != last; ++first)
60 {
61 auto && x = *first;
62 if(invoke(pred, invoke(proj, x)))
63 {
64 *o0 = (decltype(x) &&)x;
65 ++o0;
66 }
67 else
68 {
69 *o1 = (decltype(x) &&)x;
70 ++o1;
71 }
72 }
73 return {first, o0, o1};
74 }
75
77 template(typename Rng,
78 typename O0,
79 typename O1,
80 typename C,
81 typename P = identity)(
86 constexpr partition_copy_result<borrowed_iterator_t<Rng>, O0, O1> //
87 RANGES_FUNC(partition_copy)(Rng && rng, O0 o0, O1 o1, C pred, P proj = P{})
88 {
89 return (*this)(begin(rng),
90 end(rng),
91 std::move(o0),
92 std::move(o1),
93 std::move(pred),
94 std::move(proj));
95 }
96
97 RANGES_FUNC_END(partition_copy)
98
99 namespace cpp20
100 {
101 using ranges::partition_copy;
102 using ranges::partition_copy_result;
103 } // namespace cpp20
105} // namespace ranges
106
107#include <range/v3/detail/epilogue.hpp>
108
109#endif
The indirect_unary_predicate concept.
The indirectly_copyable concept.
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
The weakly_incrementable concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
front< Pair > first
Retrieve the first element of the pair Pair.
Definition meta.hpp:2251
Tiny meta-programming library.
Definition identity.hpp:25