File indexing completed on 2025-01-18 10:09:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_VIEW_REPEAT_HPP
0015 #define RANGES_V3_VIEW_REPEAT_HPP
0016
0017 #include <utility>
0018
0019 #include <range/v3/range_fwd.hpp>
0020
0021 #include <range/v3/iterator/unreachable_sentinel.hpp>
0022 #include <range/v3/range/concepts.hpp>
0023 #include <range/v3/utility/semiregular_box.hpp>
0024 #include <range/v3/utility/static_const.hpp>
0025 #include <range/v3/view/facade.hpp>
0026
0027 #include <range/v3/detail/prologue.hpp>
0028
0029 namespace ranges
0030 {
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template<typename Val>
0042 struct repeat_view : view_facade<repeat_view<Val>, infinite>
0043 {
0044 private:
0045 semiregular_box_t<Val> value_;
0046 friend range_access;
0047
0048 struct cursor
0049 {
0050 private:
0051 Val const * value_;
0052 std::ptrdiff_t n_ = 0;
0053
0054 public:
0055 cursor() = default;
0056 explicit cursor(Val const & value)
0057 : value_(std::addressof(value))
0058 {}
0059 Val const & read() const noexcept
0060 {
0061 return *value_;
0062 }
0063 bool equal(cursor const & that) const
0064 {
0065 return n_ == that.n_;
0066 }
0067 void next()
0068 {
0069 ++n_;
0070 }
0071 void prev()
0072 {
0073 --n_;
0074 }
0075 void advance(std::ptrdiff_t d)
0076 {
0077 n_ += d;
0078 }
0079 std::ptrdiff_t distance_to(cursor const & that) const
0080 {
0081 return that.n_ - n_;
0082 }
0083 };
0084 cursor begin_cursor() const
0085 {
0086 return cursor{value_};
0087 }
0088 unreachable_sentinel_t end_cursor() const
0089 {
0090 return unreachable;
0091 }
0092
0093 public:
0094 repeat_view() = default;
0095 constexpr explicit repeat_view(Val value)
0096 : value_(detail::move(value))
0097 {}
0098 };
0099
0100 namespace views
0101 {
0102 struct repeat_fn
0103 {
0104 template(typename Val)(
0105 requires copy_constructible<Val>)
0106 repeat_view<Val> operator()(Val value) const
0107 {
0108 return repeat_view<Val>{std::move(value)};
0109 }
0110 };
0111
0112
0113
0114 RANGES_INLINE_VARIABLE(repeat_fn, repeat)
0115 }
0116
0117 }
0118
0119 #include <range/v3/detail/epilogue.hpp>
0120 #include <range/v3/detail/satisfy_boost_range.hpp>
0121 RANGES_SATISFY_BOOST_RANGE(::ranges::repeat_view)
0122
0123 #endif