views::transform
C++23Apply a function to each element lazily.
Section hub
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*)
value: the value to be repeatedly producedbound: the boundvalue_args: the tuple containing the initializers of value_bound_args: the tuple containing the initializers of bound_Feature-test macro Value Std Feature __cpp_lib_ranges_repeat 202207L (C++23) std::ranges::repeat_view
#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";
}
| 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 |
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.
Start here for the adapters most people reach for first when building pipelines.
Apply a function to each element lazily.
Keep only elements that satisfy a predicate.
Keep the first N elements from a source range.
Skip the first N elements and expose the rest.
Split a range into non-overlapping fixed-size subranges.
Flatten a range of ranges into a single lazy sequence.
These adapt shape, ownership, or projection rather than representing the “headline” pipeline steps.
Normalize a range into a view-compatible form.
Adapt iterator/sentinel pairs into a common-range shape.
Wrap an existing range by reference.
Store and expose a range with unique ownership.
Package iterator + sentinel as a view-like object.
Project tuple-like elements to their key component.
Project tuple-like elements to their value component.
Newer adapters, kept as a compact scan list with only standard badges.
A lighter-weight index of the full ranges surface, grouped by conceptual task instead of raw page-tree names.