/// \file // Range v3 library // // Copyright Eric Niebler 2013-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_DROP_HPP #define RANGES_V3_VIEW_DROP_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-views /// @{ template struct RANGES_EMPTY_BASES drop_view : view_interface, is_finite::value ? finite : range_cardinality::value> , private detail::non_propagating_cache, drop_view, !random_access_range> { private: using difference_type_ = range_difference_t; Rng rng_; difference_type_ n_; template auto get_begin_(std::true_type, std::true_type) const -> CPP_ret(iterator_t>)( // requires Const && range>) { CPP_assert(random_access_range>); return next(ranges::begin(rng_), n_, ranges::end(rng_)); } iterator_t get_begin_(std::true_type, std::false_type) { CPP_assert(random_access_range); return next(ranges::begin(rng_), n_, ranges::end(rng_)); } iterator_t get_begin_(std::false_type, detail::ignore_t) { CPP_assert(!random_access_range); using cache_t = detail::non_propagating_cache, drop_view>; auto & begin_ = static_cast(*this); if(!begin_) begin_ = next(ranges::begin(rng_), n_, ranges::end(rng_)); return *begin_; } public: drop_view() = default; drop_view(Rng rng, difference_type_ n) : rng_(std::move(rng)) , n_(n) { RANGES_EXPECT(n >= 0); } iterator_t begin() { return this->get_begin_(meta::bool_>{}, std::false_type{}); } sentinel_t end() { return ranges::end(rng_); } template auto begin() const -> CPP_ret(iterator_t>)( // requires Const && random_access_range>) { return this->get_begin_(std::true_type{}, std::true_type{}); } template auto end() const -> CPP_ret(sentinel_t>)( // requires Const && random_access_range>) { return ranges::end(rng_); } CPP_member auto CPP_fun(size)()(const requires sized_range) { auto const s = ranges::size(rng_); auto const n = static_cast>(n_); return s < n ? 0 : s - n; } CPP_member auto CPP_fun(size)()(requires sized_range) { auto const s = ranges::size(rng_); auto const n = static_cast>(n_); return s < n ? 0 : s - n; } Rng base() const { return rng_; } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 template drop_view(Rng &&, range_difference_t)->drop_view>; #endif namespace views { struct drop_fn { private: friend view_access; template static constexpr auto CPP_fun(bind)(drop_fn drop, Int n)( // requires integral) { return make_pipeable(bind_back(drop, n)); } template static auto impl_(Rng && rng, range_difference_t n, input_range_tag) -> drop_view> { return {all(static_cast(rng)), n}; } template static auto impl_(Rng && rng, range_difference_t n, random_access_range_tag) -> CPP_ret(subrange, sentinel_t>)( // requires forwarding_range_ && sized_range) { return {begin(rng) + ranges::min(n, distance(rng)), end(rng)}; } public: template auto CPP_fun(operator())(Rng && rng, range_difference_t n)( const requires viewable_range && input_range) { return drop_fn::impl_(static_cast(rng), n, range_tag_of{}); } }; /// \relates drop_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, drop) } // namespace views namespace cpp20 { namespace views { using ranges::views::drop; } CPP_template(typename Rng)( // requires view_) // using drop_view = ranges::drop_view; } // namespace cpp20 /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::drop_view) #endif