|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ifndef RANGES_V3_VIEW_REPEAT_N_HPP
- #define RANGES_V3_VIEW_REPEAT_N_HPP
-
- #include <utility>
-
- #include <range/v3/range_fwd.hpp>
-
- #include <range/v3/iterator/default_sentinel.hpp>
- #include <range/v3/range/concepts.hpp>
- #include <range/v3/utility/semiregular_box.hpp>
- #include <range/v3/utility/static_const.hpp>
- #include <range/v3/view/facade.hpp>
-
- namespace ranges
- {
-
-
-
-
-
-
-
-
-
-
- template<typename Val>
- struct repeat_n_view : view_facade<repeat_n_view<Val>, finite>
- {
- private:
- friend range_access;
- semiregular_box_t<Val> value_;
- std::ptrdiff_t n_;
-
- struct cursor
- {
- private:
- Val const * value_;
- std::ptrdiff_t n_;
-
- public:
- cursor() = default;
- cursor(Val const & value, std::ptrdiff_t n)
- : value_(std::addressof(value))
- , n_(n)
- {}
- Val const & read() const
- {
- return *value_;
- }
- constexpr bool equal(default_sentinel_t) const
- {
- return 0 == n_;
- }
- bool equal(cursor const & that) const
- {
- return n_ == that.n_;
- }
- void next()
- {
- RANGES_EXPECT(0 != n_);
- --n_;
- }
- void prev()
- {
- ++n_;
- }
- void advance(std::ptrdiff_t n)
- {
- n_ -= n;
- }
- std::ptrdiff_t distance_to(cursor const & that) const
- {
- return n_ - that.n_;
- }
- };
- cursor begin_cursor() const
- {
- return {value_, n_};
- }
-
- public:
- repeat_n_view() = default;
- constexpr repeat_n_view(Val value, std::ptrdiff_t n)
- : value_(detail::move(value))
- , n_((RANGES_EXPECT(0 <= n), n))
- {}
- constexpr std::size_t size() const
- {
- return static_cast<std::size_t>(n_);
- }
- };
-
- namespace views
- {
- struct repeat_n_fn
- {
- template<typename Val>
- auto operator()(Val value, std::ptrdiff_t n) const
- -> CPP_ret(repeat_n_view<Val>)(
- requires copy_constructible<Val>)
- {
- return repeat_n_view<Val>{std::move(value), n};
- }
- };
-
-
-
- RANGES_INLINE_VARIABLE(repeat_n_fn, repeat_n)
- }
-
- }
-
- #include <range/v3/detail/satisfy_boost_range.hpp>
- RANGES_SATISFY_BOOST_RANGE(::ranges::repeat_n_view)
-
- #endif
|