You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1KB

  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. #ifndef RANGES_V3_ACTION_REMOVE_IF_HPP
  14. #define RANGES_V3_ACTION_REMOVE_IF_HPP
  15. #include <utility>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/action/action.hpp>
  18. #include <range/v3/action/erase.hpp>
  19. #include <range/v3/algorithm/remove_if.hpp>
  20. #include <range/v3/functional/bind_back.hpp>
  21. #include <range/v3/functional/identity.hpp>
  22. #include <range/v3/range/traits.hpp>
  23. #include <range/v3/utility/static_const.hpp>
  24. namespace ranges
  25. {
  26. // TODO Look at all the special cases handled by erase_if in Library Fundamentals 2
  27. /// \addtogroup group-actions
  28. /// @{
  29. namespace actions
  30. {
  31. struct remove_if_fn
  32. {
  33. private:
  34. friend action_access;
  35. template<typename C, typename P = identity>
  36. static auto CPP_fun(bind)(remove_if_fn remove_if, C pred, P proj = P{})( //
  37. requires(!range<C>))
  38. {
  39. return bind_back(remove_if, std::move(pred), std::move(proj));
  40. }
  41. public:
  42. template<typename Rng, typename C, typename P = identity>
  43. auto operator()(Rng && rng, C pred, P proj = P{}) const -> CPP_ret(Rng)( //
  44. requires forward_range<Rng> &&
  45. erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>> &&
  46. permutable<iterator_t<Rng>> &&
  47. indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
  48. {
  49. auto it = ranges::remove_if(rng, std::move(pred), std::move(proj));
  50. ranges::erase(rng, it, ranges::end(rng));
  51. return static_cast<Rng &&>(rng);
  52. }
  53. };
  54. /// \ingroup group-actions
  55. /// \sa action
  56. RANGES_INLINE_VARIABLE(action<remove_if_fn>, remove_if)
  57. } // namespace actions
  58. /// @}
  59. } // namespace ranges
  60. #endif