std::ranges::views::repeat, std::ranges::repeat_view - cppreference.com (original) (raw)
Defined in header | ||
---|---|---|
template< std::move_constructible W, 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>)) class repeat_view : public ranges::view_interface<repeat_view<W, Bound>> | (1) |
namespace views { inline constexpr /* unspecified */ repeat = /* unspecified */; } | (2) | (since C++23) |
Call signature | ||
template< class W > requires /* see below */ constexpr /* see below */ repeat( W&& value ); | (since C++23) | |
template< class W, class Bound > 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) |
A range factory that generates a sequence of elements by repeatedly producing the same value. Can be either bounded or unbounded (infinite).
views::repeat(e) and views::repeat(e, f) are expression-equivalent 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 random_access_range. If Bound
is not std::unreachable_sentinel_t, repeat_view
also models sized_range and common_range.
Contents
- 1 Customization point objects
- 2 Data members
- 3 Member functions
- 4 std::ranges::repeat_view::repeat_view
- 5 std::ranges::repeat_view::begin
- 6 std::ranges::repeat_view::end
- 7 std::ranges::repeat_view::size
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
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*) |
[edit] Member functions
(constructor) | creates a repeat_view (public member function) |
---|---|
begin | obtains the beginning iterator of a repeat_view (public member function) |
end | obtains the sentinel denoting the end of a repeat_view (public member function) |
size | obtains the size of a repeat_view if it is sized (public member function) |
Inherited from std::ranges::view_interface | |
empty | returns whether the derived view is empty, provided only if it satisfies sized_range or forward_range (public member function of std::ranges::view_interface) [edit] |
cbegin(C++23) | returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface) [edit] |
cend(C++23) | returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface) [edit] |
operator bool | returns whether the derived view is not empty, provided only if ranges::empty is applicable to it (public member function of std::ranges::view_interface) [edit] |
front | returns the first element in the derived view, provided if it satisfies forward_range (public member function of std::ranges::view_interface) [edit] |
back | returns the last element in the derived view, provided only if it satisfies bidirectional_range and common_range (public member function of std::ranges::view_interface) [edit] |
operator[] | returns the nth element in the derived view, provided only if it satisfies random_access_range (public member function of std::ranges::view_interface) [edit] |
std::ranges::repeat_view::repeat_view
repeat_view() requires std::default_initializable<W> = default; | (1) | (since C++23) |
---|---|---|
constexpr explicit repeat_view( const W& value, Bound bound = Bound() ); | (2) | (since C++23) |
constexpr explicit repeat_view( W&& value, Bound bound = Bound() ); | (3) | (since C++23) |
template < class... WArgs, class... BoundArgs > requires std::constructible_from<W, WArgs...> && std::constructible_from<Bound, BoundArgs...> constexpr explicit repeat( std::piecewise_construct_t, std::tuple<WArgs...> value_args, std::tuple<BoundArgs...> bound_args = std::tuple<>{} ); | (4) | (since C++23) |
Default-initializes
_[value](repeat%5Fview.html#value)_
and value-initializes_[bound](repeat%5Fview.html#bound)_
.Initializes
_[value](repeat%5Fview.html#value)_
with value and initializes_[bound](repeat%5Fview.html#bound)_
with bound.Initializes
_[value](repeat%5Fview.html#value)_
with std::move(value) and initializes_[bound](repeat%5Fview.html#bound)_
with bound.
Parameters
value | - | the value to be repeatedly produced |
---|---|---|
bound | - | the bound |
value_args | - | the tuple containing the initializers of value_ |
bound_args | - | the tuple containing the initializers of bound_ |
std::ranges::repeat_view::end
[edit] Deduction guides
| template< class W, class Bound = std::unreachable_sentinel_t >repeat_view( W, Bound = Bound() ) -> repeat_view<W, Bound>; | | (since C++23) | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------- |
[edit] Nested classes
| | the iterator type(exposition-only member class*) | | ---------------------------------------------------- |
[edit] Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_repeat | 202207L | (C++23) | std::ranges::repeat_view |
[edit] Example
#include #include #include 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::repeat did not decay the argument | decay the argument |
LWG 4054 | C++20 | calling views::repeat with a repeat_viewdid not create a nested repeat_view | creates a nestedrepeat_view |