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.

80 lines
2.5KB

  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_HPP
  14. #define RANGES_V3_ALGORITHM_REMOVE_HPP
  15. #include <meta/meta.hpp>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/find.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)
  33. /// \brief function template \c remove
  34. template<typename I, typename S, typename T, typename P = identity>
  35. auto RANGES_FUN_NIEBLOID(remove)(I first, S last, T const & val, P proj = P{}) //
  36. ->CPP_ret(I)( //
  37. requires permutable<I> && sentinel_for<S, I> &&
  38. indirect_relation<equal_to, projected<I, P>, T const *>)
  39. {
  40. first = find(std::move(first), last, val, std::ref(proj));
  41. if(first != last)
  42. {
  43. for(I i = next(first); i != last; ++i)
  44. {
  45. if(!(invoke(proj, *i) == val))
  46. {
  47. *first = iter_move(i);
  48. ++first;
  49. }
  50. }
  51. }
  52. return first;
  53. }
  54. /// \overload
  55. template<typename Rng, typename T, typename P = identity>
  56. auto RANGES_FUN_NIEBLOID(remove)(Rng && rng, T const & val, P proj = P{})
  57. ->CPP_ret(safe_iterator_t<Rng>)( //
  58. requires forward_range<Rng> && permutable<iterator_t<Rng>> &&
  59. indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *>)
  60. {
  61. return (*this)(begin(rng), end(rng), val, std::move(proj));
  62. }
  63. RANGES_END_NIEBLOID(remove)
  64. namespace cpp20
  65. {
  66. using ranges::remove;
  67. }
  68. /// @}
  69. } // namespace ranges
  70. #endif // include guard