On this page
std::ranges::views::repeat, std::ranges::repeat_view
Defined in header <ranges> |
||
|---|---|---|
|
(1) | (since C++23) |
|
(2) | (since C++23) |
| Call signature | ||
|
(since C++23) | |
|
(since C++23) |
views::repeat(e) and views::repeat(e, f) are expression-equivalent to (has the same effect as) repeat_view(e) and repeat_view(e, f) respectively for any suitable subexpressions e and f.
Customization point objects
The name views::repeat denotes a customization point object, which is a const function object of a literal semiregular class type. For exposition purposes, the cv-unqualified version of its type is denoted as __repeat_fn.
All instances of __repeat_fn are equal. The effects of invoking different instances of type __repeat_fn on the same arguments are equivalent, regardless of whether the expression denoting the instance is an lvalue or rvalue, and is const-qualified or not (however, a volatile-qualified instance is not required to be invocable). Thus, views::repeat can be copied freely and its copies can be used interchangeably.
Given a set of types Args..., if std::declval<Args>()... meet the requirements for arguments to views::repeat above, __repeat_fn models
std::invocable<__repeat_fn, Args...>,std::invocable<const __repeat_fn, Args...>,std::invocable<__repeat_fn&, Args...>, andstd::invocable<const __repeat_fn&, Args...>.
Otherwise, no function call operator of __repeat_fn participates in overload resolution.
Data members
| Member name | Definition |
|---|---|
value_ (private) |
The beginning value of wrapped type movable-box<W>.(exposition-only member object*) |
bound_ (private) |
The sentinel value of type Bound.(exposition-only member object*) |
Member functions
creates a repeat_view (public member function) |
|
obtains the beginning iterator of a repeat_view (public member function) |
|
obtains the sentinel denoting the end of a repeat_view (public member function) |
|
obtains the size of a repeat_view if it is sized (public member function) |
|
Inherited from |
|
|
(C++20)
|
returns whether the derived view is empty. Provided if it satisfies sized_range or forward_range. (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>) |
|
(C++20)
|
returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D>) |
|
(C++20)
|
returns the first element in the derived view. Provided if it satisfies forward_range. (public member function of std::ranges::view_interface<D>) |
|
(C++20)
|
returns the last element in the derived view. Provided if it satisfies bidirectional_range and common_range. (public member function of std::ranges::view_interface<D>) |
|
(C++20)
|
returns the nth element in the derived view. Provided if it satisfies random_access_range. (public member function of std::ranges::view_interface<D>) |
std::ranges::repeat_view::repeat_view
|
(1) | (since C++23) |
|
(2) | (since C++23) |
|
(3) | (since C++23) |
|
(4) | (since C++23) |
value_ and bound_ via their default member initializers (= W() and = Bound()).
value_ with value and initializes bound_ with bound. The behavior is undefined if Bound is not std::unreachable_sentinel_t and bool(bound >= 0) is false.
value_ with std::move(value) and initializes bound_ with bound. The behavior is undefined if Bound is not std::unreachable_sentinel_t and bool(bound >= 0) is false.
value_ and bound_ through piecewise construction.
Parameters
| value | - | the value to be repeatedly produced |
| bound | - | the bound |
std::ranges::repeat_view::begin
|
(since C++23) |
Returns an iterator initialized with std::addressof(*value_).
std::ranges::repeat_view::end
|
(1) | (since C++23) |
|
(2) | (since C++23) |
std::unreachable_sentinel.
std::ranges::repeat_view::size
|
(since C++23) |
Returns the size of the view if the view is bounded. Equivalent to return /*to-unsigned-like*/(bound_);.
The exposition-only function template to-unsigned-like converts its argument (which must be integer-like) to the corresponding unsigned version of the argument type.
Deduction guides
|
(since C++23) |
Nested classes
|
(C++23)
|
the iterator type (exposition-only member class*) |
Notes
If Bound is not std::unreachable_sentinel_t, the repeat_view models sized_range and common_range.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_ranges_repeat |
202207L | (C++23) | std::ranges::repeat_view |
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 ...
See also
|
(C++20)
|
a view consisting of a sequence generated by repeatedly incrementing an initial value(class template) (customization point object) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/repeat_view