/// \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_COUNTED_HPP #define RANGES_V3_VIEW_COUNTED_HPP #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-views /// @{ template struct counted_view : view_interface, finite> { private: friend range_access; I it_; iter_difference_t n_; public: counted_view() = default; counted_view(I it, iter_difference_t n) : it_(it) , n_(n) { RANGES_EXPECT(0 <= n_); } counted_iterator begin() const { return make_counted_iterator(it_, n_); } default_sentinel_t end() const { return {}; } auto size() const { return static_cast>(n_); } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 template counted_view(I, iter_difference_t)->counted_view; #endif namespace views { struct cpp20_counted_fn { template auto operator()(I it, iter_difference_t n) const -> CPP_ret(subrange, default_sentinel_t>)( // requires input_or_output_iterator && (!random_access_iterator)) { return {make_counted_iterator(std::move(it), n), default_sentinel}; } template auto operator()(I it, iter_difference_t n) const -> CPP_ret(subrange)( // requires random_access_iterator) { return {it, it + n}; } }; struct counted_fn { template auto operator()(I it, iter_difference_t n) const -> CPP_ret(counted_view)( // requires input_or_output_iterator && (!random_access_iterator)) { return {std::move(it), n}; } template auto operator()(I it, iter_difference_t n) const -> CPP_ret(subrange)( // requires random_access_iterator) { return {it, it + n}; } }; /// \relates counted_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(counted_fn, counted) } // namespace views namespace cpp20 { namespace views { RANGES_INLINE_VARIABLE(ranges::views::cpp20_counted_fn, counted) } } // namespace cpp20 /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::counted_view) #endif