| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Eric Niebler 2013-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 |
|
| 14 |
#ifndef RANGES_V3_ACTION_REMOVE_IF_HPP |
| 15 |
#define RANGES_V3_ACTION_REMOVE_IF_HPP |
| 16 |
|
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include <range/v3/range_fwd.hpp> |
| 20 |
|
| 21 |
#include <range/v3/action/action.hpp> |
| 22 |
#include <range/v3/action/erase.hpp> |
| 23 |
#include <range/v3/algorithm/remove_if.hpp> |
| 24 |
#include <range/v3/functional/bind_back.hpp> |
| 25 |
#include <range/v3/functional/identity.hpp> |
| 26 |
#include <range/v3/range/traits.hpp> |
| 27 |
#include <range/v3/utility/static_const.hpp> |
| 28 |
|
| 29 |
#include <range/v3/detail/prologue.hpp> |
| 30 |
|
| 31 |
namespace ranges |
| 32 |
{ |
| 33 |
// TODO Look at all the special cases handled by erase_if in Library Fundamentals 2 |
| 34 |
|
| 35 |
/// \addtogroup group-actions |
| 36 |
/// @{ |
| 37 |
namespace actions |
| 38 |
{ |
| 39 |
struct 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(remove_if_fn{}, std::move(pred), std::move(proj))); |
| 47 |
} |
| 48 |
|
| 49 |
template(typename Rng, typename C, typename P = identity)( |
| 50 |
requires forward_range<Rng> AND |
| 51 |
erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>> AND |
| 52 |
permutable<iterator_t<Rng>> AND |
| 53 |
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>) |
| 54 |
Rng operator()(Rng && rng, C pred, P proj = P{}) const |
| 55 |
{ |
| 56 |
auto it = ranges::remove_if(rng, std::move(pred), std::move(proj)); |
| 57 |
ranges::erase(rng, it, ranges::end(rng)); |
| 58 |
return static_cast<Rng &&>(rng); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
/// \relates actions::remove_if_fn |
| 63 |
RANGES_INLINE_VARIABLE(remove_if_fn, remove_if) |
| 64 |
} // namespace actions |
| 65 |
/// @} |
| 66 |
} // namespace ranges |
| 67 |
|
| 68 |
#include <range/v3/detail/epilogue.hpp> |
| 69 |
|
| 70 |
#endif |