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.

85 lines
2.7KB

  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_COPY_HPP
  14. #define RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
  15. #include <meta/meta.hpp>
  16. #include <range/v3/range_fwd.hpp>
  17. #include <range/v3/algorithm/result_types.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/traits.hpp>
  22. #include <range/v3/range/access.hpp>
  23. #include <range/v3/range/concepts.hpp>
  24. #include <range/v3/range/dangling.hpp>
  25. #include <range/v3/range/traits.hpp>
  26. #include <range/v3/utility/static_const.hpp>
  27. namespace ranges
  28. {
  29. /// \addtogroup group-algorithms
  30. /// @{
  31. template<typename I, typename O>
  32. using remove_copy_result = detail::in_out_result<I, O>;
  33. RANGES_BEGIN_NIEBLOID(remove_copy)
  34. /// \brief function template \c remove_copy
  35. template<typename I, typename S, typename O, typename T, typename P = identity>
  36. auto RANGES_FUN_NIEBLOID(remove_copy)(
  37. I first, S last, O out, T const & val, P proj = P{}) //
  38. ->CPP_ret(remove_copy_result<I, O>)( //
  39. requires input_iterator<I> && sentinel_for<S, I> &&
  40. weakly_incrementable<O> &&
  41. indirect_relation<equal_to, projected<I, P>, T const *> &&
  42. indirectly_copyable<I, O>)
  43. {
  44. for(; first != last; ++first)
  45. {
  46. auto && x = *first;
  47. if(!(invoke(proj, x) == val))
  48. {
  49. *out = (decltype(x) &&)x;
  50. ++out;
  51. }
  52. }
  53. return {first, out};
  54. }
  55. /// \overload
  56. template<typename Rng, typename O, typename T, typename P = identity>
  57. auto RANGES_FUN_NIEBLOID(remove_copy)(
  58. Rng && rng, O out, T const & val, P proj = P{}) //
  59. ->CPP_ret(remove_copy_result<safe_iterator_t<Rng>, O>)( //
  60. requires input_range<Rng> && weakly_incrementable<O> &&
  61. indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *> &&
  62. indirectly_copyable<iterator_t<Rng>, O>)
  63. {
  64. return (*this)(begin(rng), end(rng), std::move(out), val, std::move(proj));
  65. }
  66. RANGES_END_NIEBLOID(remove_copy)
  67. namespace cpp20
  68. {
  69. using ranges::remove_copy;
  70. using ranges::remove_copy_result;
  71. } // namespace cpp20
  72. /// @}
  73. } // namespace ranges
  74. #endif // include guard