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
expression-equivalentto
repeat_view<std::decay_t<decltype((E))>>(e)and
repeat_view(e, f)respectively for any suitable subexpressions
eand
f.
repeat_view
models random_access_range
. If Bound
is not std::unreachable_sentinel_t, repeat_view
also models sized_range
and common_range
.
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.
movable-box
<W> value_
the repeating element of the view
Bound
bound_
the sentinel value
repeat_view
repeat_view
repeat_view
repeat_view
if it is sized
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] returns the n
th element in the derived view, provided only if it satisfies random_access_range
std::ranges::view_interface<D>
) [edit] std::ranges::repeat_view::repeat_view 1)
Default-initializes
value_
and value-initializes
bound_
.
2)Initializes
value_
with
valueand initializes
bound_
with
bound.
3)Initializes
value_
with
std::move(value)and initializes
bound_
with
bound.
Parameters value - the value to be repeatedly produced bound - the bound value_args - the tuple containing the initializers ofvalue_
bound_args - the tuple containing the initializers of bound_
std::ranges::repeat_view::end [edit] Deduction guides (since C++23) [edit] Nested classes the iterator type
#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 toviews::repeat
did not decay the argument decay the argument LWG 4054 C++20 calling views::repeat
with a repeat_view
repeat_view
creates a nested
repeat_view
[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4