| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Andrey Diduh 2019 |
| 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_ACTION_UNSTABLE_REMOVE_IF_HPP |
| 14 |
#define RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP |
| 15 |
|
| 16 |
#include <utility> |
| 17 |
|
| 18 |
#include <concepts/concepts.hpp> |
| 19 |
|
| 20 |
#include <range/v3/range_fwd.hpp> |
| 21 |
|
| 22 |
#include <range/v3/action/action.hpp> |
| 23 |
#include <range/v3/action/erase.hpp> |
| 24 |
#include <range/v3/algorithm/unstable_remove_if.hpp> |
| 25 |
#include <range/v3/functional/bind_back.hpp> |
| 26 |
#include <range/v3/functional/identity.hpp> |
| 27 |
#include <range/v3/iterator/concepts.hpp> |
| 28 |
#include <range/v3/range/access.hpp> |
| 29 |
#include <range/v3/range/concepts.hpp> |
| 30 |
|
| 31 |
#include <range/v3/detail/prologue.hpp> |
| 32 |
|
| 33 |
namespace ranges |
| 34 |
{ |
| 35 |
/// \addtogroup group-actions |
| 36 |
/// @{ |
| 37 |
namespace actions |
| 38 |
{ |
| 39 |
struct unstable_remove_if_fn |
| 40 |
{ |
| 41 |
template(typename C, typename P = identity)( |
| 42 |
requires (!range<C>)) |
| 43 |
constexpr auto operator()(C pred, P proj = P{}) const |
| 44 |
{ |
| 45 |
return make_action_closure( |
| 46 |
bind_back(unstable_remove_if_fn{}, std::move(pred), std::move(proj))); |
| 47 |
} |
| 48 |
|
| 49 |
template(typename Rng, typename C, typename P = identity)( |
| 50 |
requires bidirectional_range<Rng> AND common_range<Rng> AND |
| 51 |
permutable<iterator_t<Rng>> AND |
| 52 |
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND |
| 53 |
erasable_range<Rng, iterator_t<Rng>, iterator_t<Rng>>) |
| 54 |
Rng operator()(Rng && rng, C pred, P proj = P{}) const |
| 55 |
{ |
| 56 |
auto it = ranges::unstable_remove_if(ranges::begin(rng), |
| 57 |
ranges::end(rng), |
| 58 |
std::move(pred), |
| 59 |
std::move(proj)); |
| 60 |
ranges::erase(rng, it, ranges::end(rng)); |
| 61 |
return static_cast<Rng &&>(rng); |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
/// \sa `actions::unstable_remove_if_fn` |
| 66 |
RANGES_INLINE_VARIABLE(unstable_remove_if_fn, unstable_remove_if) |
| 67 |
} // namespace actions |
| 68 |
/// @} |
| 69 |
} // namespace ranges |
| 70 |
|
| 71 |
#include <range/v3/detail/epilogue.hpp> |
| 72 |
|
| 73 |
#endif // RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP |