From cppreference.com
Defined in header
template<std::move_constructibleW,std::semiregularBound=std::unreachable_sentinel_t>requires(std::is_object_v<W>&&std::same_as<W,std::remove_cv_t<W>>&&(/*integer-like-with-usable-difference-type*/<Bound>||std::same_as<Bound,std::unreachable_sentinel_t>))classrepeat_view:publicranges::view_interface<repeat_view<W,Bound>> (1) (since C++23)namespaceviews{inlineconstexpr/* unspecified */repeat=/* unspecified */;} (2) (since C++23)Call signature
template<classW>requires/* see below */constexpr/* see below */repeat(W&&value);(since C++23)template<classW,classBound>requires/* see below */constexpr/* see below */repeat(W&&value,Bound&&bound);(since C++23)Helper concepts
concept/*integer-like-with-usable-difference-type*/=/*is-signed-integer-like*/<T>||(/*is-integer-like*/<T>&&std::weakly_incrementable<T>) (3)(exposition only*)1) A range factory that generates a sequence of elements by repeatedly producing the same value. Can be either bounded or unbounded (infinite).
2)views::repeat(e) and views::repeat(e,f) are
to repeat_view<std::decay_t<decltype((E))>>(e) and repeat_view(e,f) respectively for any suitable subexpressions e and f.
repeat_view models
. If Bound is not
, repeat_view also models
and
.
Customization point objects
The name views::repeat denotes a customization point object, which is a const
of a
class type. See
for details.
Data members
Member Definition
<W>value_the repeating element of the view
(exposition-only member object*)Boundbound_the sentinel value
(exposition-only member object*)Member functions
creates a repeat_view
(public member function)
obtains the beginning iterator of a
(public member function)
obtains the sentinel denoting the end of a
(public member function)
obtains the size of a
if it is sized
(public member function) Inherited from
returns whether the derived view is empty, provided only if it satisfies
or
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a constant iterator to the beginning of the range
(public member function of std::ranges::view_interface<D>)
(C++23)
returns a sentinel for the constant iterator of the range
(public member function of std::ranges::view_interface<D>)
returns whether the derived view is not empty, provided only if
is applicable to it
(public member function of std::ranges::view_interface<D>)
returns the first element in the derived view, provided if it satisfies
(public member function of std::ranges::view_interface<D>)
returns the last element in the derived view, provided only if it satisfies
and
(public member function of std::ranges::view_interface<D>)
returns the nth element in the derived view, provided only if it satisfies
(public member function of std::ranges::view_interface<D>)
std::ranges::repeat_view::repeat_view
repeat_view()requiresstd::default_initializable<W>=default; (1) (since C++23)constexprexplicitrepeat_view(constW&value,Boundbound=Bound()); (2) (since C++23)constexprexplicitrepeat_view(W&&value,Boundbound=Bound()); (3) (since C++23)template<class...WArgs,class...BoundArgs>requiresstd::constructible_from<W,WArgs...>&&std::constructible_from<Bound,BoundArgs...>constexprexplicitrepeat(std::piecewise_construct_t,std::tuple<WArgs...>value_args,std::tuple<BoundArgs...>bound_args=std::tuple<>{}); (4) (since C++23)1) Default-initializes
and value-initializes
.
2) Initializes
with value and initializes
with bound.
3) Initializes
with std::move(value) and initializes
with bound.
4) Initializes
with std::make_from_tuple<T>(std::move(value_args)) and
with std::make_from_tuple<Bound>(std::move(bound_args)).
Parameters
value - the value to be repeatedly produced bound - the bound value_args - the tuple containing the initializers of
bound_args - the tuple containing the initializers of
std::ranges::repeat_view::begin
constexpr/*iterator*/begin()const;(since C++23)Returns
(std::addressof(*
)).
std::ranges::repeat_view::end
constexpr/*iterator*/end()constrequires(!std::same_as<Bound,std::unreachable_sentinel_t>); (1) (since C++23)constexprstd::unreachable_sentinel_tend()const; (2) (since C++23)1) Returns
(std::addressof(*
),
).
2) Returns std::unreachable_sentinel.
std::ranges::repeat_view::size
constexprautosize()constrequires(!std::same_as<Bound,std::unreachable_sentinel_t>);(since C++23)Returns
(
).
Deduction guides
template<classW,classBound=std::unreachable_sentinel_t>repeat_view(W,Bound=Bound())->repeat_view<W,Bound>;(since C++23)Nested classes
the iterator type
(exposition-only member class*)Notes
macroValueStdFeature
(C++23)
Example
Run this code
#include<iostream>#include<ranges>#include<string_view>usingnamespacestd::literals;intmain(){// bounded overloadfor(autos:std::views::repeat("C++"sv,3))std::cout<<s<<' ';std::cout<<'\n';// unbounded overloadfor(autos:std::views::repeat("I know that you know that"sv)|std::views::take(3))std::cout<<s<<' ';std::cout<<"...\n";}Output:
C++ C++ C++ I know that you know that I know that you know that I know that you know that ... Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++20 unary calls to views::repeat did not decay the argument decay the argument
C++20 calling views::repeat with a repeat_view
did not create a nested repeat_viewcreates a nested
repeat_viewSee also