drop.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <range/v3/detail/prologue.hpp>
  24. namespace ranges
  25. {
  26. /// \addtogroup group-actions
  27. /// @{
  28. namespace actions
  29. {
  30. struct drop_fn
  31. {
  32. template(typename Int)(
  33. requires detail::integer_like_<Int>)
  34. constexpr auto operator()(Int n) const
  35. {
  36. RANGES_EXPECT(n >= Int(0));
  37. return make_action_closure(bind_back(drop_fn{}, n));
  38. }
  39. template(typename Rng)(
  40. requires forward_range<Rng> AND
  41. erasable_range<Rng &, iterator_t<Rng>, iterator_t<Rng>>)
  42. Rng operator()(Rng && rng, range_difference_t<Rng> n) const
  43. {
  44. RANGES_EXPECT(n >= 0);
  45. ranges::actions::erase(
  46. rng, begin(rng), ranges::next(begin(rng), n, end(rng)));
  47. return static_cast<Rng &&>(rng);
  48. }
  49. };
  50. /// \relates actions::drop_fn
  51. RANGES_INLINE_VARIABLE(drop_fn, drop)
  52. } // namespace actions
  53. /// @}
  54. } // namespace ranges
  55. #include <range/v3/detail/epilogue.hpp>
  56. #endif