/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_TAIL_HPP #define RANGES_V3_VIEW_TAIL_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { namespace detail { template constexpr T prev_or_zero_(T n) { return n == 0 ? T(0) : T(n - 1); } } // namespace detail /// \addtogroup group-views /// @{ template struct tail_view : view_interface, (range_cardinality::value >= 0) ? detail::prev_or_zero_(range_cardinality::value) : range_cardinality::value> { private: Rng rng_; public: tail_view() = default; tail_view(Rng rng) : rng_(static_cast(rng)) { CPP_assert(input_range); } iterator_t begin() { return next(ranges::begin(rng_), 1, ranges::end(rng_)); } template auto begin() const -> CPP_ret(iterator_t>)( // requires Const && range>) { return next(ranges::begin(rng_), 1, ranges::end(rng_)); } sentinel_t end() { return ranges::end(rng_); } template auto end() const -> CPP_ret(sentinel_t>)( // requires Const && range>) { return ranges::end(rng_); } CPP_member constexpr auto CPP_fun(size)()(requires sized_range) { using size_type = range_size_t; return range_cardinality::value >= 0 ? detail::prev_or_zero_((size_type)range_cardinality::value) : detail::prev_or_zero_(ranges::size(rng_)); } CPP_member constexpr auto CPP_fun(size)()(const requires sized_range) { using size_type = range_size_t; return range_cardinality::value >= 0 ? detail::prev_or_zero_((size_type)range_cardinality::value) : detail::prev_or_zero_(ranges::size(rng_)); } Rng base() const { return rng_; } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 CPP_template(typename Rng)(requires viewable_range) tail_view(Rng &&) ->tail_view>; #endif namespace views { struct tail_fn { template auto operator()(Rng && rng) const -> CPP_ret(meta::if_c::value == 0, all_t, tail_view>>)( // requires viewable_range && input_range) { return all(static_cast(rng)); } }; /// \relates tail_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, tail) } // namespace views /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::tail_view) #endif