Debian Codegraph @

3rd_party/range-v3/range/v3/action/take.hpp

raw
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
14 #ifndef RANGES_V3_ACTION_TAKE_HPP
15 #define RANGES_V3_ACTION_TAKE_HPP
16
17 #include <range/v3/range_fwd.hpp>
18
19 #include <range/v3/action/action.hpp>
20 #include <range/v3/action/erase.hpp>
21 #include <range/v3/functional/bind_back.hpp>
22 #include <range/v3/iterator/concepts.hpp>
23 #include <range/v3/iterator/operations.hpp>
24 #include <range/v3/iterator/traits.hpp>
25 #include <range/v3/utility/static_const.hpp>
26
27 #include <range/v3/detail/prologue.hpp>
28
29 namespace ranges
30 {
31 /// \addtogroup group-actions
32 /// @{
33 namespace actions
34 {
35 struct take_fn
36 {
37 template(typename Int)(
38 requires detail::integer_like_<Int>)
39 constexpr auto operator()(Int n) const
40 {
41 return make_action_closure(bind_back(take_fn{}, n));
42 }
43
44 template(typename Rng)(
45 requires forward_range<Rng> AND
46 erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>>)
47 Rng operator()(Rng && rng, range_difference_t<Rng> n) const
48 {
49 RANGES_EXPECT(n >= 0);
50 ranges::actions::erase(
51 rng, ranges::next(begin(rng), n, end(rng)), end(rng));
52 return static_cast<Rng &&>(rng);
53 }
54 };
55
56 /// \relates actions::take_fn
57 RANGES_INLINE_VARIABLE(take_fn, take)
58 } // namespace actions
59 /// @}
60 } // namespace ranges
61
62 #include <range/v3/detail/epilogue.hpp>
63
64 #endif