[range.repeat]

# 25 Ranges library [[ranges]](./#ranges)

## 25.6 Range factories [[range.factories]](range.factories#range.repeat)

### 25.6.5 Repeat view [range.repeat]

#### [25.6.5.1](#overview) Overview [[range.repeat.overview]](range.repeat.overview)

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3559)

repeat_view generates a sequence of elements
by repeatedly producing the same value[.](#overview-1.sentence-1)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3563)

The name views​::​repeat denotes
a customization point object ([[customization.point.object]](customization.point.object "16.3.3.3.5 Customization Point Object types"))[.](#overview-2.sentence-1)

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[.](#overview-2.sentence-2)

[3](#overview-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3572)

[*Example [1](#overview-example-1)*: for (int i : views::repeat(17, 4)) cout << i << ' ';// prints 17 17 17 17 â *end example*]

#### [25.6.5.2](#view) Class template repeat_view [[range.repeat.view]](range.repeat.view)

namespace std::ranges {template<class T>concept [*integer-like-with-usable-difference-type*](#concept:integer-like-with-usable-difference-type "25.6.5.2 Class template repeat_­view [range.repeat.view]") = // *exposition only**is-signed-integer-like*<T> || (*is-integer-like*<T> && [weakly_incrementable](iterator.concept.winc#concept:weakly_incrementable "24.3.4.4 Concept weakly_­incrementable [iterator.concept.winc]")<T>); template<[move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13 Concept move_­constructible [concept.moveconstructible]") T, [semiregular](concepts.object#concept:semiregular "18.6 Object concepts [concepts.object]") Bound = unreachable_sentinel_t>requires (is_object_v<T> && [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<T, remove_cv_t<T>> &&([*integer-like-with-usable-difference-type*](#concept:integer-like-with-usable-difference-type "25.6.5.2 Class template repeat_­view [range.repeat.view]")<Bound> ||[same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>))class [repeat_view](#lib:repeat_view "25.6.5.2 Class template repeat_­view [range.repeat.view]") : public view_interface<repeat_view<T, Bound>> {private:// [[range.repeat.iterator]](#iterator "25.6.5.3 Class repeat_­view​::​iterator"), class repeat_view​::​*iterator*struct *iterator*; // *exposition only**movable-box*<T> *value_*; // *exposition only*, see [[range.move.wrap]](range.move.wrap "25.7.3 Movable wrapper") Bound *bound_* = Bound(); // *exposition only*public: repeat_view() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<T> = default; constexpr explicit repeat_view(const T& value, Bound bound = Bound())requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<T>; constexpr explicit repeat_view(T&& value, Bound bound = Bound()); template<class... TArgs, class... BoundArgs>requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]")<T, TArgs...> &&[constructible_from](concept.constructible#concept:constructible_from "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<>{}); constexpr *iterator* begin() const; constexpr *iterator* end() const requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>); constexpr unreachable_sentinel_t end() const noexcept; constexpr auto size() const requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>); }; template<class T, class Bound = unreachable_sentinel_t> repeat_view(T, Bound = Bound()) -> repeat_view<T, Bound>;}

[ð](#lib:repeat_view,constructor)

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

[1](#view-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3632)

*Preconditions*: If Bound is not unreachable_sentinel_t,bound â¥ 0[.](#view-1.sentence-1)

[2](#view-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3637)

*Effects*: Initializes *value_* with value and*bound_* with bound[.](#view-2.sentence-1)

[ð](#lib:repeat_view,constructor_)

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

[3](#view-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3649)

*Preconditions*: If Bound is not unreachable_sentinel_t, bound â¥ 0[.](#view-3.sentence-1)

[4](#view-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3653)

*Effects*: Initializes *value_* with std​::​move(value) and*bound_* with bound[.](#view-4.sentence-1)

[ð](#lib:repeat_view,constructor__)

`template<class... TArgs, class... BoundArgs>
  requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]")<T, TArgs...> &&
           [constructible_from](concept.constructible#concept:constructible_from "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<>{});
`

[5](#view-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3669)

*Effects*: Initializes *value_* withmake_from_tuple<T>(std​::​move(value_args)) and
initializes *bound_* withmake_from_tuple<Bound>(std​::​move(bound_args))[.](#view-5.sentence-1)

The behavior is undefined ifBound is not unreachable_sentinel_t and*bound_* is negative[.](#view-5.sentence-2)

[ð](#lib:begin,repeat_view)

`constexpr iterator begin() const;
`

[6](#view-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3687)

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

[ð](#lib:end,repeat_view)

`constexpr iterator end() const requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>);
`

[7](#view-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3698)

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

[ð](#lib:end,repeat_view_)

`constexpr unreachable_sentinel_t end() const noexcept;
`

[8](#view-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3709)

*Effects*: Equivalent to: return unreachable_sentinel;

[ð](#lib:size,repeat_view)

`constexpr auto size() const requires (![same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>);
`

[9](#view-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3720)

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

#### [25.6.5.3](#iterator) Class repeat_view​::​*iterator* [[range.repeat.iterator]](range.repeat.iterator)

[ð](#lib:repeat_view::iterator)

namespace std::ranges {template<[move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13 Concept move_­constructible [concept.moveconstructible]") T, [semiregular](concepts.object#concept:semiregular "18.6 Object concepts [concepts.object]") Bound>requires (is_object_v<T> && [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<T, remove_cv_t<T>> &&([*integer-like-with-usable-difference-type*](#concept:integer-like-with-usable-difference-type "25.6.5.2 Class template repeat_­view [range.repeat.view]")<Bound> ||[same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>))class repeat_view<T, Bound>::*iterator* {private:using *index-type* = // *exposition only* conditional_t<[same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>; const T* *value_* = nullptr; // *exposition only**index-type* *current_* = *index-type*(); // *exposition only*constexpr explicit *iterator*(const T* 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 = 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); };}

[1](#iterator-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3775)

If *is-signed-integer-like*<*index-type*> is true,
the member [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") difference_type denotes *index-type*[.](#iterator-1.sentence-1)

Otherwise, it denotes *IOTA-DIFF-T*(*index-type*) ([[range.iota.view]](range.iota.view "25.6.4.2 Class template iota_­view"))[.](#iterator-1.sentence-2)

[ð](#lib:repeat_view::iterator,constructor)

`constexpr explicit iterator(const T* value, index-type b = index-type());
`

[2](#iterator-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3787)

*Preconditions*: If Bound is not unreachable_sentinel_t, b â¥ 0[.](#iterator-2.sentence-1)

[3](#iterator-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3791)

*Effects*: Initializes *value_* with value and*current_* with b[.](#iterator-3.sentence-1)

[ð](#lib:operator*,repeat_view::iterator)

`constexpr const T& operator*() const noexcept;
`

[4](#iterator-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3803)

*Effects*: Equivalent to: return **value_*;

[ð](#lib:operator++,repeat_view::iterator)

`constexpr iterator& operator++();
`

[5](#iterator-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3814)

*Effects*: Equivalent to:++*current_*;return *this;

[ð](#lib:operator++,repeat_view::iterator_)

`constexpr iterator operator++(int);
`

[6](#iterator-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3829)

*Effects*: Equivalent to:auto tmp = *this;++*this;return tmp;

[ð](#lib:operator--,repeat_view::iterator)

`constexpr iterator& operator--();
`

[7](#iterator-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3845)

*Preconditions*: If Bound is not unreachable_sentinel_t,current_>0[.](#iterator-7.sentence-1)

[8](#iterator-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3850)

*Effects*: Equivalent to:--*current_*;return *this;

[ð](#lib:operator--,repeat_view::iterator_)

`constexpr iterator operator--(int);
`

[9](#iterator-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3865)

*Effects*: Equivalent to:auto tmp = *this;--*this;return tmp;

[ð](#lib:operator+=,repeat_view::iterator)

`constexpr iterator& operator+=(difference_type n);
`

[10](#iterator-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3881)

*Preconditions*: If Bound is not unreachable_sentinel_t,current_+nâ¥0[.](#iterator-10.sentence-1)

[11](#iterator-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3886)

*Effects*: Equivalent to:*current_* += n;return *this;

[ð](#lib:operator-=,repeat_view::iterator)

`constexpr iterator& operator-=(difference_type n);
`

[12](#iterator-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3901)

*Preconditions*: If Bound is not unreachable_sentinel_t,current_ânâ¥0[.](#iterator-12.sentence-1)

[13](#iterator-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3906)

*Effects*: Equivalent to:*current_* -= n;return *this;

[ð](#lib:operator%5b%5d,repeat_view::iterator)

`constexpr const T& operator[](difference_type n) const noexcept;
`

[14](#iterator-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3921)

*Effects*: Equivalent to: return *(*this + n);

[ð](#lib:operator==,repeat_view::iterator)

`friend constexpr bool operator==(const iterator& x, const iterator& y);
`

[15](#iterator-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3932)

*Effects*: Equivalent to: return x.*current_* == y.*current_*;

[ð](#lib:operator%3c=%3e,repeat_view::iterator)

`friend constexpr auto operator<=>(const iterator& x, const iterator& y);
`

[16](#iterator-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3943)

*Effects*: Equivalent to: return x.*current_* <=> y.*current_*;

[ð](#lib:operator+,repeat_view::iterator)

`friend constexpr iterator operator+(iterator i, difference_type n);
friend constexpr iterator operator+(difference_type n, iterator i);
`

[17](#iterator-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3955)

*Effects*: Equivalent to:i += n;return i;

[ð](#lib:operator-,repeat_view::iterator)

`friend constexpr iterator operator-(iterator i, difference_type n);
`

[18](#iterator-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3970)

*Effects*: Equivalent to:i -= n;return i;

[ð](#lib:operator-,repeat_view::iterator_)

`friend constexpr difference_type operator-(const iterator& x, const iterator& y);
`

[19](#iterator-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L3985)

*Effects*: Equivalent to:return static_cast<difference_type>(x.*current_*) - static_cast<difference_type>(y.*current_*);
