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.

99 lines
3.1KB

  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_VIEW_REMOVE_HPP
  14. #define RANGES_V3_VIEW_REMOVE_HPP
  15. #include <type_traits>
  16. #include <utility>
  17. #include <meta/meta.hpp>
  18. #include <concepts/concepts.hpp>
  19. #include <range/v3/range_fwd.hpp>
  20. #include <range/v3/functional/bind_back.hpp>
  21. #include <range/v3/functional/comparisons.hpp>
  22. #include <range/v3/functional/pipeable.hpp>
  23. #include <range/v3/view/remove_if.hpp>
  24. #include <range/v3/view/view.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-views
  28. /// @{
  29. namespace views
  30. {
  31. struct remove_fn
  32. {
  33. private:
  34. friend view_access;
  35. template<typename Value>
  36. static constexpr auto bind(remove_fn remove, Value value)
  37. {
  38. return make_pipeable(bind_back(remove, std::move(value)));
  39. }
  40. template<typename Value, typename Proj>
  41. static constexpr auto CPP_fun(bind)(remove_fn remove, Value value,
  42. Proj proj)( //
  43. requires(!range<Value>))
  44. {
  45. return make_pipeable(
  46. bind_back(remove, std::move(value), std::move(proj)));
  47. }
  48. template<typename Value>
  49. struct pred
  50. {
  51. Value value_;
  52. template<typename T>
  53. auto operator()(T && other) const -> CPP_ret(bool)( //
  54. requires equality_comparable_with<T, Value const &>)
  55. {
  56. return static_cast<T &&>(other) == value_;
  57. }
  58. };
  59. public:
  60. template<typename Rng, typename Value>
  61. constexpr auto CPP_fun(operator())(Rng && rng, Value value)(
  62. const requires move_constructible<Value> && viewable_range<Rng> &&
  63. input_range<Rng> &&
  64. indirectly_comparable<iterator_t<Rng>, Value const *, equal_to>)
  65. {
  66. return remove_if(static_cast<Rng &&>(rng), pred<Value>{std::move(value)});
  67. }
  68. template<typename Rng, typename Value, typename Proj>
  69. constexpr auto CPP_fun(operator())(Rng && rng, Value value, Proj proj)(
  70. const requires move_constructible<Value> && viewable_range<Rng> &&
  71. input_range<Rng> && indirectly_comparable<
  72. iterator_t<Rng>, Value const *, equal_to, Proj>)
  73. {
  74. return remove_if(static_cast<Rng &&>(rng),
  75. pred<Value>{std::move(value)},
  76. std::move(proj));
  77. }
  78. };
  79. /// \relates remove_fn
  80. /// \ingroup group-views
  81. RANGES_INLINE_VARIABLE(view<remove_fn>, remove)
  82. } // namespace views
  83. /// @}
  84. } // namespace ranges
  85. #endif // RANGES_V3_VIEW_REMOVE_HPP