Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:59

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Barry Revzin 2019-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
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     /// \addtogroup group-views
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         /// \relates take_last_fn
0059         RANGES_INLINE_VARIABLE(take_last_fn, take_last)
0060     } // namespace views
0061     /// @}
0062 } // namespace ranges
0063 
0064 #include <range/v3/detail/epilogue.hpp>
0065 
0066 #endif