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.

73 line
2.3KB

  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. namespace ranges
  25. {
  26. /// \addtogroup group-actions
  27. /// @{
  28. namespace actions
  29. {
  30. struct remove_fn
  31. {
  32. private:
  33. friend action_access;
  34. template<typename V, typename P>
  35. static auto CPP_fun(bind)(remove_fn remove, V && value, P proj)( //
  36. requires(!range<V>))
  37. {
  38. return bind_back(remove, static_cast<V &&>(value), std::move(proj));
  39. }
  40. template<typename V>
  41. static auto bind(remove_fn remove, V && value)
  42. {
  43. return bind_back(remove, static_cast<V &&>(value), identity{});
  44. }
  45. public:
  46. template<typename Rng, typename V, typename P = identity>
  47. auto operator()(Rng && rng, V const & value, P proj = {}) const
  48. -> CPP_ret(Rng)( //
  49. requires forward_range<Rng> && permutable<iterator_t<Rng>> &&
  50. erasable_range<Rng, iterator_t<Rng>, sentinel_t<Rng>> &&
  51. indirect_relation<equal_to, projected<iterator_t<Rng>, P>,
  52. V const *>)
  53. {
  54. auto it = ranges::remove(rng, value, std::move(proj));
  55. ranges::erase(rng, it, ranges::end(rng));
  56. return static_cast<Rng &&>(rng);
  57. }
  58. };
  59. /// \ingroup group-actions
  60. /// \sa action
  61. /// \sa with_braced_init_args
  62. RANGES_INLINE_VARIABLE(action<remove_fn>, remove)
  63. } // namespace actions
  64. /// @}
  65. } // namespace ranges
  66. #endif // include guard