remove.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_REMOVE_HPP
  14. #define RANGES_V3_ACTION_REMOVE_HPP
  15. #include <meta/meta.hpp>
  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.hpp>
  20. #include <range/v3/functional/bind_back.hpp>
  21. #include <range/v3/range/concepts.hpp>
  22. #include <range/v3/range/traits.hpp>
  23. #include <range/v3/utility/static_const.hpp>
  24. #include <range/v3/detail/prologue.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-actions
  28. /// @{
  29. namespace actions
  30. {
  31. struct remove_fn
  32. {
  33. template(typename V, typename P)(
  34. requires (!range<V>))
  35. constexpr auto operator()(V && value, P proj) const
  36. {
  37. return make_action_closure(
  38. bind_back(remove_fn{}, static_cast<V &&>(value), std::move(proj)));
  39. }
  40. template<typename V>
  41. constexpr auto operator()(V && value) const
  42. {
  43. return make_action_closure(
  44. bind_back(remove_fn{}, static_cast<V &&>(value), identity{}));
  45. }
  46. template(typename Rng, typename V, typename P = identity)(
  47. requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
  48. erasable_range<Rng, iterator_t<Rng>, sentinel_t<Rng>> AND
  49. indirect_relation<equal_to, projected<iterator_t<Rng>, P>,
  50. V const *>)
  51. Rng operator()(Rng && rng, V const & value, P proj = {}) const
  52. {
  53. auto it = ranges::remove(rng, value, std::move(proj));
  54. ranges::erase(rng, it, ranges::end(rng));
  55. return static_cast<Rng &&>(rng);
  56. }
  57. };
  58. /// \relates actions::remove_fn
  59. RANGES_INLINE_VARIABLE(remove_fn, remove)
  60. } // namespace actions
  61. /// @}
  62. } // namespace ranges
  63. #include <range/v3/detail/epilogue.hpp>
  64. #endif