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.

75 satır
2.5KB

  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_UNSTABLE_REMOVE_IF_HPP
  14. #define RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP
  15. #include <utility>
  16. #include <concepts/concepts.hpp>
  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/unstable_remove_if.hpp>
  21. #include <range/v3/functional/bind_back.hpp>
  22. #include <range/v3/functional/identity.hpp>
  23. #include <range/v3/iterator/concepts.hpp>
  24. #include <range/v3/range/access.hpp>
  25. #include <range/v3/range/concepts.hpp>
  26. namespace ranges
  27. {
  28. /// \addtogroup group-actions
  29. /// @{
  30. namespace actions
  31. {
  32. struct unstable_remove_if_fn
  33. {
  34. private:
  35. friend action_access;
  36. template<typename C, typename P = identity>
  37. static auto CPP_fun(bind)(unstable_remove_if_fn unstable_remove_if, C pred,
  38. P proj = P{})( //
  39. requires(!range<C>))
  40. {
  41. return bind_back(unstable_remove_if, std::move(pred), std::move(proj));
  42. }
  43. public:
  44. template<typename Rng, typename C, typename P = identity>
  45. auto operator()(Rng && rng, C pred, P proj = P{}) const -> CPP_ret(Rng)( //
  46. requires bidirectional_range<Rng> && common_range<Rng> &&
  47. permutable<iterator_t<Rng>> &&
  48. indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> &&
  49. erasable_range<Rng, iterator_t<Rng>, iterator_t<Rng>>)
  50. {
  51. auto it = ranges::unstable_remove_if(ranges::begin(rng),
  52. ranges::end(rng),
  53. std::move(pred),
  54. 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 `actions::unstable_remove_if_fn`
  62. RANGES_INLINE_VARIABLE(action<unstable_remove_if_fn>, unstable_remove_if)
  63. } // namespace actions
  64. /// @}
  65. } // namespace ranges
  66. #endif // RANGES_V3_ACTION_UNSTABLE_REMOVE_IF_HPP