/// \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_EXACTLY_HPP #define RANGES_V3_VIEW_DROP_EXACTLY_HPP #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_exactly_view : view_interface, is_finite::value ? finite : range_cardinality::value> , private detail::non_propagating_cache, drop_exactly_view, !random_access_range> { private: using difference_type_ = range_difference_t; Rng rng_; difference_type_ n_; // random_access_range == true template auto get_begin_(std::true_type) const -> CPP_ret(iterator_t>)( // requires Const && random_access_range>) { return next(ranges::begin(rng_), n_); } iterator_t get_begin_(std::true_type) { return next(ranges::begin(rng_), n_); } // random_access_range == false iterator_t get_begin_(std::false_type) { using cache_t = detail::non_propagating_cache, drop_exactly_view>; auto & begin_ = static_cast(*this); if(!begin_) begin_ = next(ranges::begin(rng_), n_); return *begin_; } public: drop_exactly_view() = default; drop_exactly_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_>{}); } 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{}); } 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) { return ranges::size(rng_) - static_cast>(n_); } CPP_member auto CPP_fun(size)()(requires sized_range) { return ranges::size(rng_) - static_cast>(n_); } Rng base() const { return rng_; } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 template drop_exactly_view(Rng &&, range_difference_t) ->drop_exactly_view>; #endif namespace views { struct drop_exactly_fn { private: friend view_access; template static constexpr auto CPP_fun(bind)(drop_exactly_fn drop_exactly, Int n)( // requires integral) { return make_pipeable(bind_back(drop_exactly, n)); } template static auto impl_(Rng && rng, range_difference_t n, input_range_tag) -> drop_exactly_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_) { return {begin(rng) + n, end(rng)}; } public: template auto CPP_fun(operator())(Rng && rng, range_difference_t n)( const requires viewable_range && input_range) { return drop_exactly_fn::impl_( static_cast(rng), n, range_tag_of{}); } }; /// \relates drop_exactly_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, drop_exactly) } // namespace views /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::drop_exactly_view) #endif