26 Ranges library [ranges]

26.6 Range factories [range.factories]

26.6.5 Repeat view [range.repeat]

26.6.5.1 Overview [range.repeat.overview]

repeat_­view generates a sequence of elements by repeatedly producing the same value.
The name views​::​repeat denotes a customization point object ([customization.point.object]).
Given subexpressions E and F, the expressions views​::​repeat(E) and views​::​repeat(E, F) are expression-equivalent to repeat_­view(E) and repeat_­view(E, F), respectively.
[Example 1: for (int i : views::repeat(17, 4)) cout << i << ' '; // prints 17 17 17 17 — end example]

26.6.5.2 Class template repeat_­view [range.repeat.view]

namespace std::ranges { template<move_­constructible W, semiregular Bound = unreachable_sentinel_t> requires (is_object_v<W> && same_­as<W, remove_cv_t<W>> && (is-integer-like<Bound> || same_­as<Bound, unreachable_sentinel_t>)) class repeat_view : public view_interface<repeat_view<W, Bound>> { private: // [range.repeat.iterator], class repeat_­view​::​iterator struct iterator; // exposition only movable-box<W> value_ = W(); // exposition only, see [range.move.wrap] Bound bound_ = Bound(); // exposition only public: repeat_view() requires default_­initializable<W> = default; constexpr explicit repeat_view(const W& value, Bound bound = Bound()) requires copy_­constructible<W>; constexpr explicit repeat_view(W&& value, Bound bound = Bound()); template<class... WArgs, class... BoundArgs> requires constructible_­from<W, WArgs...> && constructible_­from<Bound, BoundArgs...> constexpr explicit repeat_view(piecewise_construct_t, tuple<WArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{}); constexpr iterator begin() const; constexpr iterator end() const requires (!same_­as<Bound, unreachable_sentinel_t>); constexpr unreachable_sentinel_t end() const noexcept; constexpr auto size() const requires (!same_­as<Bound, unreachable_sentinel_t>); }; template<class W, class Bound> repeat_view(W, Bound) -> repeat_view<W, Bound>; }
constexpr explicit repeat_view(const W& value, Bound bound = Bound()) requires copy_­constructible<W>;
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Initializes value_­ with value and bound_­ with bound.
constexpr explicit repeat_view(W&& value, Bound bound = Bound());
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Initializes value_­ with std​::​move(value) and bound_­ with bound.
template<class... WArgs, class... BoundArgs> requires constructible_­from<W, WArgs...> && constructible_­from<Bound, BoundArgs...> constexpr explicit repeat_view(piecewise_construct_t, tuple<Wargs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});
Effects: Initializes value_­ with arguments of types WArgs... obtained by forwarding the elements of value_­args and initializes bound_­ with arguments of types BoundArgs... obtained by forwarding the elements of bound_­args.
(Here, forwarding an element x of type U within a tuple object means calling std​::​forward<U>(x).)
constexpr iterator begin() const;
Effects: Equivalent to: return iterator(addressof(*value_­));
constexpr iterator end() const requires (!same_­as<Bound, unreachable_sentinel_t>);
Effects: Equivalent to: return iterator(addressof(*value_­), bound_­);
constexpr unreachable_sentinel_t end() const noexcept;
Effects: Equivalent to: return unreachable_­sentinel;
constexpr auto size() const requires (!same_­as<Bound, unreachable_sentinel_t>);
Effects: Equivalent to: return to-unsigned-like(bound_­);

26.6.5.3 Class repeat_­view​::​iterator [range.repeat.iterator]

namespace std::ranges { template<move_­constructible W, semiregular Bound = unreachable_sentinel_t> requires (is_object_v<W> && same_­as<W, remove_cv_t<W>> && (is-integer-like<Bound> || same_­as<Bound, unreachable_sentinel_t>)) class repeat_view<W, Bound>::iterator { private: using index-type = // exposition only conditional_t<same_­as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>; const W* value_ = nullptr; // exposition only index-type current_ = index-type(); // exposition only constexpr explicit iterator(const W* value, index-type b = index-type()); // exposition only public: using iterator_concept = random_access_iterator_tag; using iterator_category = random_access_iterator_tag; using value_type = W; using difference_type = conditional_t<is-signed-integer-like<index-type>, index-type, IOTA-DIFF-T(index-type)>; iterator() = default; constexpr const W& operator*() const noexcept; constexpr iterator& operator++(); constexpr iterator operator++(int); constexpr iterator& operator--(); constexpr iterator operator--(int); constexpr iterator& operator+=(difference_type n); constexpr iterator& operator-=(difference_type n); constexpr const W& operator[](difference_type n) const noexcept; friend constexpr bool operator==(const iterator& x, const iterator& y); friend constexpr auto operator<=>(const iterator& x, const iterator& y); friend constexpr iterator operator+(iterator i, difference_type n); friend constexpr iterator operator+(difference_type n, iterator i); friend constexpr iterator operator-(iterator i, difference_type n); friend constexpr difference_type operator-(const iterator& x, const iterator& y); }; }
constexpr explicit iterator(const W* value, index-type b = index-type());
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Initializes value_­ with value and current_­ with b.
constexpr const W& operator*() const noexcept;
Effects: Equivalent to: return *value_­;
constexpr iterator& operator++();
Effects: Equivalent to: ++current_; return *this;
constexpr iterator operator++(int);
Effects: Equivalent to: auto tmp = *this; ++*this; return tmp;
constexpr iterator& operator--();
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Equivalent to: --current_; return *this;
constexpr iterator operator--(int);
Effects: Equivalent to: auto tmp = *this; --*this; return tmp;
constexpr iterator& operator+=(difference_type n);
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Equivalent to: current_ += n; return *this;
constexpr iterator& operator-=(difference_type n);
Preconditions: If Bound is not unreachable_­sentinel_­t, .
Effects: Equivalent to: current_ -= n; return *this;
constexpr const W& operator[](difference_type n) const noexcept;
Effects: Equivalent to: return *(*this + n);
friend constexpr bool operator==(const iterator& x, const iterator& y);
Effects: Equivalent to: return x.current_­ == y.current_­;.
friend constexpr auto operator<=>(const iterator& x, const iterator& y);
Effects: Equivalent to: return x.current_­ <=> y.current_­;.
friend constexpr iterator operator+(iterator i, difference_type n); friend constexpr iterator operator+(difference_type n, iterator i);
Effects: Equivalent to: i += n; return i;
friend constexpr iterator operator-(iterator i, difference_type n);
Effects: Equivalent to: i -= n; return i;
friend constexpr difference_type operator-(const iterator& x, const iterator& y);
Effects: Equivalent to: return static_cast<difference_type>(x.current_) - static_cast<difference_type>(y.current_);