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.

71 lines
2.3KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler
  5. // Copyright Christopher Di Bella
  6. //
  7. // Use, modification and distribution is subject to the
  8. // Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. // Project home: https://github.com/ericniebler/range-v3
  13. //
  14. #ifndef RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP
  15. #define RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP
  16. #include <utility>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/action/action.hpp>
  19. #include <range/v3/action/erase.hpp>
  20. #include <range/v3/algorithm/adjacent_remove_if.hpp>
  21. #include <range/v3/functional/bind_back.hpp>
  22. #include <range/v3/functional/identity.hpp>
  23. #include <range/v3/range/traits.hpp>
  24. #include <range/v3/utility/static_const.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-actions
  28. /// @{
  29. namespace actions
  30. {
  31. struct adjacent_remove_if_fn
  32. {
  33. private:
  34. friend action_access;
  35. template<typename Pred, typename Proj = identity>
  36. static auto CPP_fun(bind)(adjacent_remove_if_fn adjacent_remove_if, Pred pred,
  37. Proj proj = {})( //
  38. requires(!range<Pred>))
  39. {
  40. return bind_back(adjacent_remove_if, std::move(pred), std::move(proj));
  41. }
  42. public:
  43. template<typename Rng, typename Pred, typename Proj = identity>
  44. auto operator()(Rng && rng, Pred pred, Proj proj = {}) const
  45. -> CPP_ret(Rng)( //
  46. requires forward_range<Rng> &&
  47. erasable_range<Rng, iterator_t<Rng>, sentinel_t<Rng>> &&
  48. indirect_relation<Pred, projected<iterator_t<Rng>, Proj>> &&
  49. permutable<iterator_t<Rng>>)
  50. {
  51. auto i = adjacent_remove_if(rng, std::move(pred), std::move(proj));
  52. erase(rng, std::move(i), end(rng));
  53. return static_cast<Rng &&>(rng);
  54. }
  55. };
  56. /// \ingroup group-actions
  57. /// \sa action
  58. /// \sa with_braced_init_args
  59. RANGES_INLINE_VARIABLE(action<adjacent_remove_if_fn>, adjacent_remove_if)
  60. } // namespace actions
  61. /// @}
  62. } // namespace ranges
  63. #endif // RANGES_V3_ACTION_ADJACENT_REMOVE_IF_HPP