File indexing completed on 2025-01-18 10:09:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_VIEW_TAKE_LAST_HPP
0015 #define RANGES_V3_VIEW_TAKE_LAST_HPP
0016
0017 #include <concepts/concepts.hpp>
0018
0019 #include <range/v3/range_fwd.hpp>
0020
0021 #include <range/v3/functional/bind_back.hpp>
0022 #include <range/v3/range/concepts.hpp>
0023 #include <range/v3/range/operations.hpp>
0024 #include <range/v3/view/drop_exactly.hpp>
0025
0026 #include <range/v3/detail/prologue.hpp>
0027
0028 namespace ranges
0029 {
0030
0031
0032
0033 namespace views
0034 {
0035 struct take_last_base_fn
0036 {
0037 template(typename Rng)(
0038 requires viewable_range<Rng> AND sized_range<Rng>)
0039 auto operator()(Rng && rng, range_difference_t<Rng> n) const
0040 {
0041 auto sz = ranges::distance(rng);
0042 return drop_exactly(static_cast<Rng &&>(rng), sz > n ? sz - n : 0);
0043 }
0044 };
0045
0046 struct take_last_fn : take_last_base_fn
0047 {
0048 using take_last_base_fn::operator();
0049
0050 template(typename Int)(
0051 requires detail::integer_like_<Int>)
0052 constexpr auto operator()(Int n) const
0053 {
0054 return make_view_closure(bind_back(take_last_base_fn{}, n));
0055 }
0056 };
0057
0058
0059 RANGES_INLINE_VARIABLE(take_last_fn, take_last)
0060 }
0061
0062 }
0063
0064 #include <range/v3/detail/epilogue.hpp>
0065
0066 #endif