[range.repeat] (original) (raw)

25 Ranges library [ranges]

25.6 Range factories [range.factories]

25.6.5 Repeat view [range.repeat]

25.6.5.1 Overview [range.repeat.overview]

repeat_view generates a sequence of elements by repeatedly producing the same value.

Given subexpressions E and F, the expressions views​::​repeat(E) and views​::​repeat(E, F)are expression-equivalent torepeat_view<decay_t<decltype((E))>>(E) and repeat_view(E, F), respectively.

[Example 1: for (int i : views::repeat(17, 4)) cout << i << ' '; — _end example_]

25.6.5.2 Class template repeat_view [range.repeat.view]

namespace std::ranges { template<class T> concept integer-like-with-usable-difference-type = is-signed-integer-like<T> || (is-integer-like<T> && weakly_incrementable<T>);template<move_constructible T, semiregular Bound = unreachable_sentinel_t> requires (is_object_v<T> && same_as<T, remove_cv_t<T>> && (integer-like-with-usable-difference-type<Bound> || same_as<Bound, unreachable_sentinel_t>)) class repeat_view : public view_interface<repeat_view<T, Bound>> { private: struct iterator; movable-box<T> value_; Bound bound_ = Bound(); public: repeat_view() requires default_initializable<T> = default;constexpr explicit repeat_view(const T& value, Bound bound = Bound()) requires copy_constructible<T>;constexpr explicit repeat_view(T&& value, Bound bound = Bound());template<class... TArgs, class... BoundArgs> requires constructible_from<T, TArgs...> && constructible_from<Bound, BoundArgs...> constexpr explicit repeat_view(piecewise_construct_t, tuple<TArgs...> 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 T, class Bound = unreachable_sentinel_t> repeat_view(T, Bound = Bound()) -> repeat_view<T, Bound>;}

constexpr explicit repeat_view(const T& value, Bound bound = Bound()) requires [copy_constructible](concept.copyconstructible#concept:copy%5Fconstructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<T>;

Preconditions: If Bound is not unreachable_sentinel_t,bound ≥ 0.

Effects: Initializes value_ with value and_bound__ with bound.

constexpr explicit repeat_view(T&& value, Bound bound = Bound());

Preconditions: If Bound is not unreachable_sentinel_t, bound ≥ 0.

Effects: Initializes value_ with std​::​move(value) and_bound__ with bound.

template<class... TArgs, class... BoundArgs> requires [constructible_from](concept.constructible#concept:constructible%5Ffrom "18.4.11 Concept constructible_­from [concept.constructible]")<T, TArgs...> && [constructible_from](concept.constructible#concept:constructible%5Ffrom "18.4.11 Concept constructible_­from [concept.constructible]")<Bound, BoundArgs...> constexpr explicit repeat_view(piecewise_construct_t, tuple<TArgs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});

Effects: Initializes value_ withmake_from_tuple<T>(std​::​move(value_args))and initializes bound_ withmake_from_tuple<Bound>(std​::​move(bound_args)).

The behavior is undefined ifBound is not unreachable_sentinel_t and_bound__ is negative.

constexpr _iterator_ begin() const;

Effects: Equivalent to: return iterator(addressof(*value_));

constexpr _iterator_ end() const requires (![same_as](concept.same#concept:same%5Fas "18.4.2 Concept same_­as [concept.same]")<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](concept.same#concept:same%5Fas "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>);

Effects: Equivalent to: return to-unsigned-like(bound_);

25.6.5.3 Class repeat_view​::​iterator [range.repeat.iterator]

namespace std::ranges { template<move_constructible T, semiregular Bound> requires (is_object_v<T> && same_as<T, remove_cv_t<T>> && (integer-like-with-usable-difference-type<Bound> || same_as<Bound, unreachable_sentinel_t>)) class repeat_view<T, Bound>::iterator { private: using index-type = conditional_t<same_as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>;const T* value_ = nullptr; index-type current_ = index-type(); constexpr explicit iterator(const T* value, index-type b = index-type()); public: using iterator_concept = random_access_iterator_tag;using iterator_category = random_access_iterator_tag;using value_type = T;using difference_type = see below;iterator() = default;constexpr const T& 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 T& 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);};}

If is-signed-integer-like<_index-type_> is true, the member typedef-name difference_typedenotes index-type.

constexpr explicit _iterator_(const T* value, _index-type_ b = _index-type_());

Preconditions: If Bound is not unreachable_sentinel_t, b ≥ 0.

Effects: Initializes value_ with value and_current__ with b.

constexpr const T& 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 T& 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_);