Horizon
partition_copy.hpp
Go to the documentation of this file.
1 // 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 
20 #include <range/v3/range_fwd.hpp>
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 
36 namespace 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)(
82  requires input_range<Rng> AND weakly_incrementable<O0> AND
83  weakly_incrementable<O1> AND indirectly_copyable<iterator_t<Rng>, O0> AND
85  indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
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
template(typename Rng, typename O0, typename O1, typename C, typename P=identity)(requires input_range< Rng > AND weakly_incrementable< O0 > AND weakly_incrementable< O1 > AND indirectly_copyable< iterator_t< Rng >
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPP_concept sentinel_for
\concept sentinel_for
Definition: concepts.hpp:306
CPP_concept indirect_unary_predicate
\concept indirect_unary_predicate
Definition: concepts.hpp:632
CPP_concept input_iterator
\concept input_iterator
Definition: concepts.hpp:362
CPP_concept indirectly_copyable
\concept indirectly_copyable
Definition: concepts.hpp:782
CPP_concept weakly_incrementable
\concept weakly_incrementable
Definition: concepts.hpp:268
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
front< Pair > first
Retrieve the first element of the pair Pair.
Definition: meta.hpp:2251
Tiny meta-programming library.
Definition: identity.hpp:25