|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
template<std::move_constructible W, std::semiregular Bound=std::unreachable_sentinel_t> | (1) | (since C++23) |
namespace views{ inlineconstexpr/* unspecified */ repeat=/* unspecified */; | (2) | (since C++23) |
Call signature | ||
template<class W> requires/* see below */ | (since C++23) | |
template<class W,class Bound> requires/* see below */ | (since C++23) | |
Helper concepts | ||
concept/*integer-like-with-usable-difference-type*/= /*is-signed-integer-like*/<T>|| | (3) | (exposition only*) |
repeat_view
modelsrandom_access_range
. IfBound
is notstd::unreachable_sentinel_t,repeat_view
also modelssized_range
andcommon_range
.
Contents |
The nameviews::repeat
denotes acustomization point object, which is a constfunction object of aliteralsemiregular
class type. SeeCustomizationPointObject for details.
Member | Definition |
movable-box <W>value_ | the repeating element of the view (exposition-only member object*) |
Bound bound_ | the sentinel value (exposition-only member object*) |
creates arepeat_view (public member function) | |
obtains the beginning iterator of arepeat_view (public member function) | |
obtains the sentinel denoting the end of arepeat_view (public member function) | |
obtains the size of arepeat_view if it is sized(public member function) | |
Inherited fromstd::ranges::view_interface | |
returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
(C++23) | returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface<D> )[edit] |
(C++23) | returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface<D> )[edit] |
returns whether the derived view is not empty, provided only ifranges::empty is applicable to it (public member function of std::ranges::view_interface<D> )[edit] | |
returns the first element in the derived view, provided if it satisfiesforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns then th element in the derived view, provided only if it satisfiesrandom_access_range (public member function of std::ranges::view_interface<D> )[edit] |
repeat_view() requiresstd::default_initializable<W>=default; | (1) | (since C++23) |
constexprexplicit repeat_view(const W& value, Bound bound= Bound()); | (2) | (since C++23) |
constexprexplicit repeat_view( W&& value, Bound bound= Bound()); | (3) | (since C++23) |
template<class...WArgs,class...BoundArgs> requiresstd::constructible_from<W, WArgs...> | (4) | (since C++23) |
value_
withstd::make_from_tuple<T>(std::move(value_args)) andbound_
withstd::make_from_tuple<Bound>(std::move(bound_args)).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 ofbound_ |
constexpr/*iterator*/ begin()const; | (since C++23) | |
Returnsiterator
(std::addressof(*value_
)).
constexpr/*iterator*/ end()const requires(!std::same_as<Bound,std::unreachable_sentinel_t>); | (1) | (since C++23) |
constexprstd::unreachable_sentinel_t end()const; | (2) | (since C++23) |
iterator
(std::addressof(*value_
),
bound_
).constexprauto size()const requires(!std::same_as<Bound,std::unreachable_sentinel_t>); | (since C++23) | |
Returnsto-unsigned-like
(bound_
).
template<class W,class Bound=std::unreachable_sentinel_t> repeat_view( W, Bound= Bound())-> repeat_view<W, Bound>; | (since C++23) | |
the iterator type (exposition-only member class*) |
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_repeat | 202207L | (C++23) | std::ranges::repeat_view |
#include <iostream>#include <ranges>#include <string_view>usingnamespace std::literals; int main(){// bounded overloadfor(auto s: std::views::repeat("C++"sv,3))std::cout<< s<<' ';std::cout<<'\n'; // unbounded overloadfor(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 ...
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 | callingviews::repeat with arepeat_view did not create a nested repeat_view | creates a nestedrepeat_view |
(C++20) | aview consisting of a sequence generated by repeatedly incrementing an initial value(class template)(customization point object)[edit] |