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.

преди 5 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2014-present
  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_ALGORITHM_REMOVE_IF_HPP
  14. #define RANGES_V3_ALGORITHM_REMOVE_IF_HPP
  15. #include <meta/meta.hpp>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/find_if.hpp>
  18. #include <range/v3/functional/identity.hpp>
  19. #include <range/v3/functional/invoke.hpp>
  20. #include <range/v3/iterator/concepts.hpp>
  21. #include <range/v3/iterator/operations.hpp>
  22. #include <range/v3/iterator/traits.hpp>
  23. #include <range/v3/range/access.hpp>
  24. #include <range/v3/range/concepts.hpp>
  25. #include <range/v3/range/dangling.hpp>
  26. #include <range/v3/range/traits.hpp>
  27. #include <range/v3/utility/static_const.hpp>
  28. namespace ranges
  29. {
  30. /// \addtogroup group-algorithms
  31. /// @{
  32. RANGES_BEGIN_NIEBLOID(remove_if)
  33. /// \brief function template \c remove_if
  34. template<typename I, typename S, typename C, typename P = identity>
  35. auto RANGES_FUN_NIEBLOID(remove_if)(I first, S last, C pred, P proj = P{}) //
  36. ->CPP_ret(I)( //
  37. requires permutable<I> && sentinel_for<S, I> &&
  38. indirect_unary_predicate<C, projected<I, P>>)
  39. {
  40. first = find_if(std::move(first), last, std::ref(pred), std::ref(proj));
  41. if(first != last)
  42. {
  43. for(I i = next(first); i != last; ++i)
  44. {
  45. if(!(invoke(pred, invoke(proj, *i))))
  46. {
  47. *first = iter_move(i);
  48. ++first;
  49. }
  50. }
  51. }
  52. return first;
  53. }
  54. /// \overload
  55. template<typename Rng, typename C, typename P = identity>
  56. auto RANGES_FUN_NIEBLOID(remove_if)(Rng && rng, C pred, P proj = P{}) //
  57. ->CPP_ret(safe_iterator_t<Rng>)( //
  58. requires forward_range<Rng> && permutable<iterator_t<Rng>> &&
  59. indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
  60. {
  61. return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
  62. }
  63. RANGES_END_NIEBLOID(remove_if)
  64. namespace cpp20
  65. {
  66. using ranges::remove_if;
  67. }
  68. /// @}
  69. } // namespace ranges
  70. #endif // include guard