std::ranges...:repeat_view(3)
π std::ranges...:repeat_view(3) π
okay bestie, welcome to the C++ Standard Libary manual page for std::ranges::views::repeat and std::ranges::repeat_view β yes, both, they're besties. this one is a range factory, and it's lowkey iconic. π
β¨ NAME β¨
std::ranges::views::repeat, std::ranges::repeat_view β std::ranges::views::repeat, std::ranges::repeat_view
πΈ Synopsis πΈ
Defined in header <ranges>.
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>> &&
(/*is-integer-like*/<Bound> ||
std::same_as<Bound, std::unreachable_sentinel_t>))
class repeat_view : public ranges::view_interface<repeat_view<W, Bound>>
(1) (since C++23)
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)
- 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)andviews::repeat(e, f)are expression-equivalent to (has the same effect as)repeat_view(e)andrepeat_view(e, f)respectively for any suitable subexpressionseandf.
repeat_view models random_access_range. If Bound is not std::unreachable_sentinel_t, repeat_view also models sized_range and common_range.
π Member functions π
constructorβ creates arepeat_view(public member function)beginβ obtains the beginning iterator of arepeat_view(public member function)endβ obtains the sentinel denoting the end of arepeat_view(public member function)sizeβ obtains the size of arepeat_viewif it is sized (public member function)
π«Ά Inherited from std::ranges::view_interface
empty(C++20) β returns whether the derived view is empty. Provided if it satisfiessized_rangeorforward_range. (public member function ofstd::ranges::view_interface<D>)cbegin(C++23) β returns a constant iterator to the beginning of the range. (public member function ofstd::ranges::view_interface<D>)cend(C++23) β returns a sentinel for the constant iterator of the range. (public member function ofstd::ranges::view_interface<D>)operator bool(C++20) β returns whether the derived view is not empty. Provided ifranges::emptyis applicable to it. (public member function ofstd::ranges::view_interface<D>)front(C++20) β returns the first element in the derived view. Provided if it satisfiesforward_range. (public member function ofstd::ranges::view_interface<D>)back(C++20) β returns the last element in the derived view. Provided if it satisfiesbidirectional_rangeandcommon_range. (public member function ofstd::ranges::view_interface<D>)operator[](C++20) β returns the n^th element in the derived view. Provided if it satisfiesrandom_access_range. (public member function ofstd::ranges::view_interface<D>)
π 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)
- Value-initializes
value_andbound_via their default member initializers (= W()and= Bound()). - Initializes
value_withvalueand initializesbound_withbound. The behavior is undefined ifBoundis notstd::unreachable_sentinel_tandbool(bound >= 0)is false. - Initializes
value_withstd::move(value)and initializesbound_withbound. The behavior is undefined ifBoundis notstd::unreachable_sentinel_tandbool(bound >= 0)is false. - Initializes
value_andbound_through piecewise construction.
π― Parameters π―
valueβ the value to be repeatedly producedboundβ the bound
π std::ranges::repeat_view::begin π
constexpr /*iterator*/ begin() const;
(since C++23)
Returns an iterator initialized with std::addressof(*value_).
π std::ranges::repeat_view::end π
constexpr /*iterator*/ end() const
requires (!std::same_as<Bound, std::unreachable_sentinel_t>);
(1) (since C++23)
constexpr std::unreachable_sentinel_t end() const;
(2) (since C++23)
- Returns an iterator initialized with
std::addressof(*value_)andbound_. - Returns an
std::unreachable_sentinel.
π std::ranges::repeat_view::size π
constexpr auto size() const
requires (!std::same_as<Bound, std::unreachable_sentinel_t>);
(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 π§
template< class W, class Bound >
repeat_view( W, Bound ) -> repeat_view<W, Bound>;
(since C++23)
πͺ Nested classes πͺ
iterator(C++23) β the iterator type (exposition-only member class*)
π Notes π
- Feature-test macro
__cpp_lib_ranges_repeat, value202207L, Std(C++23), featurestd::ranges::repeat_view.
π» Example π»
// Run this code
#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 π
ranges::iota_view(C++20) β a view consisting of a sequence generated by repeatedly incrementing an initial value; (class template)views::iota(C++20) β a view consisting of a sequence generated by repeatedly incrementing an initial value; (customization point object)
okay that's the whole page, bestie! source: cppreference.com, version/date 2024.06.10, manual page std::ranges...:repeat_view(3). slay and happy ranging! πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms