| 1 |
/// \file |
| 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 |
|
| 20 |
#include <range/v3/range_fwd.hpp> |
| 21 |
|
| 22 |
#include <range/v3/algorithm/result_types.hpp> |
| 23 |
#include <range/v3/functional/identity.hpp> |
| 24 |
#include <range/v3/functional/invoke.hpp> |
| 25 |
#include <range/v3/iterator/concepts.hpp> |
| 26 |
#include <range/v3/iterator/operations.hpp> |
| 27 |
#include <range/v3/iterator/traits.hpp> |
| 28 |
#include <range/v3/range/access.hpp> |
| 29 |
#include <range/v3/range/concepts.hpp> |
| 30 |
#include <range/v3/range/dangling.hpp> |
| 31 |
#include <range/v3/range/traits.hpp> |
| 32 |
#include <range/v3/utility/static_const.hpp> |
| 33 |
|
| 34 |
#include <range/v3/detail/prologue.hpp> |
| 35 |
|
| 36 |
namespace ranges |
| 37 |
{ |
| 38 |
/// \addtogroup group-algorithms |
| 39 |
/// @{ |
| 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 |
/// \brief function template \c partition_copy |
| 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 |
| 53 |
weakly_incrementable<O0> AND weakly_incrementable<O1> 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 |
|
| 76 |
/// \overload |
| 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 |
| 84 |
indirectly_copyable<iterator_t<Rng>, O1> 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 |
| 104 |
/// @} |
| 105 |
} // namespace ranges |
| 106 |
|
| 107 |
#include <range/v3/detail/epilogue.hpp> |
| 108 |
|
| 109 |
#endif |