Section hub

std::ranges::views::repeat, std::ranges::repeat_view

  1. A range factory that generates a sequence of elements by repeatedly producing the same value. Can be either bounded or unbounded (infinite).

# Declarations

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>>

(since C++23)

namespace views {
inline constexpr /* unspecified */ repeat = /* unspecified */;
}

(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>)

(exposition only*)

# 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_

# Notes

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";
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 4053C++20unary calls to views::repeat did not decay the argumentdecay the argument
LWG 4054C++20calling views::repeat with a repeat_viewdid not create a nested repeat_viewcreates a nestedrepeat_view

# See also

This hub groups the ranges library by user task rather than by raw reference tree shape. View types and adaptor objects are presented as the same conceptual item.

Core adapters

Start here for the adapters most people reach for first when building pipelines.

Utility views

These adapt shape, ownership, or projection rather than representing the “headline” pipeline steps.

New in C++23 / C++26

Newer adapters, kept as a compact scan list with only standard badges.

All entities by category

A lighter-weight index of the full ranges surface, grouped by conceptual task instead of raw page-tree names.

74 entities