std::ranges::views::repeat, std::ranges::repeat_view
          <ranges> 
           std::semiregular Bound = 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 >))
    inline constexpr /* unspecified */ repeat = /* unspecified */;
    requires /* see below */
    requires /* see below */
    /*is-signed-integer-like*/<T> ||
repeat_view models random_access_range. If Bound is not std::unreachable_sentinel_t , repeat_view also models sized_range and common_range.
Contents
Customization point objects
The name views::repeat denotes a customization point object, which is a const function object of a literal semiregular class type. See CustomizationPointObject for details.
[edit] Data members
Bound bound_
 the sentinel value(exposition-only member object*)
[edit] Member functions
Inherited from std::ranges::view_interface
sized_range or forward_range (public member function of
std::ranges::view_interface<D>) [edit] 
(public member function of
std::ranges::view_interface<D>) [edit] 
(public member function of
std::ranges::view_interface<D>) [edit] 
(public member function of
std::ranges::view_interface<D>) [edit] 
forward_range (public member function of
std::ranges::view_interface<D>) [edit] 
bidirectional_range and common_range (public member function of
std::ranges::view_interface<D>) [edit] 
nth element in the derived view, provided only if it satisfies random_access_range (public member function of
std::ranges::view_interface<D>) [edit] 
std::ranges::repeat_view::repeat_view
    requires std::constructible_from <W, WArgs...>
          && std::constructible_from <Bound, BoundArgs...>
constexpr explicit
    repeat( std::piecewise_construct_t, std::tuple <WArgs...> value_args,
Bound is not std::unreachable_sentinel_t  and bool(bound >= 0) is false, the behavior is undefined.Bound is not std::unreachable_sentinel_t  and bool(bound >= 0) is false, the behavior is undefined.value_  with std::make_from_tuple <T>(std::move(value_args)) and bound_  with std::make_from_tuple <Bound>(std::move(bound_args)).Bound is not std::unreachable_sentinel_t  and bool(bound >= 0) is false, the behavior is undefined.Parameters
value_ 
bound_ 
std::ranges::repeat_view::begin
Returns iterator (std::addressof (*value_  )).
std::ranges::repeat_view::end
requires (!std::same_as <Bound, std::unreachable_sentinel_t >);
iterator (std::addressof (*value_  ), bound_  ).
std::ranges::repeat_view::size
requires (!std::same_as <Bound, std::unreachable_sentinel_t >);
Returns to-unsigned-like  (bound_  ).
[edit] Deduction guides
repeat_view( W, Bound = Bound() ) -> repeat_view<W, Bound>;
[edit] Nested classes
[edit] Notes
| Feature-test macro | Value | Std | Feature | 
|---|---|---|---|
| __cpp_lib_ranges_repeat | 202207L | (C++23) | std::ranges::repeat_view | 
[edit] Example
#include <iostream> #include <ranges> #include <string_view> using namespace std::literals; int main() { // bounded overload for (auto s : std::views::repeat("C++"sv, 3)) std::cout << s << ' '; std::cout << '\n'; // unbounded overload for (auto s : 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 ...
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| LWG 4053 | C++20 | unary calls to views::repeatdid not decay the argument | decay the argument | 
| LWG 4054 | C++20 | calling views::repeatwith arepeat_viewdid not create a nested repeat_view | creates a nested repeat_view |