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.

drop.hpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-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_ACTION_DROP_HPP
  14. #define RANGES_V3_ACTION_DROP_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/action/action.hpp>
  17. #include <range/v3/action/erase.hpp>
  18. #include <range/v3/functional/bind_back.hpp>
  19. #include <range/v3/iterator/concepts.hpp>
  20. #include <range/v3/iterator/operations.hpp>
  21. #include <range/v3/iterator/traits.hpp>
  22. #include <range/v3/utility/static_const.hpp>
  23. namespace ranges
  24. {
  25. /// \addtogroup group-actions
  26. /// @{
  27. namespace actions
  28. {
  29. struct drop_fn
  30. {
  31. private:
  32. friend action_access;
  33. template<typename Int>
  34. static auto CPP_fun(bind)(drop_fn drop, Int n)( //
  35. requires integral<Int>)
  36. {
  37. return bind_back(drop, n);
  38. }
  39. public:
  40. template<typename Rng>
  41. auto operator()(Rng && rng, range_difference_t<Rng> n) const
  42. -> CPP_ret(Rng)( //
  43. requires forward_range<Rng> &&
  44. erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>>)
  45. {
  46. RANGES_EXPECT(n >= 0);
  47. ranges::actions::erase(
  48. rng, begin(rng), ranges::next(begin(rng), n, end(rng)));
  49. return static_cast<Rng &&>(rng);
  50. }
  51. };
  52. /// \ingroup group-actions
  53. /// \relates drop_fn
  54. /// \sa action
  55. RANGES_INLINE_VARIABLE(action<drop_fn>, drop)
  56. } // namespace actions
  57. /// @}
  58. } // namespace ranges
  59. #endif