views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::input_range V >
requires ranges::view<V>
class stride_view
: public ranges::view_interface<stride_view<V>>
(since C++23)
namespace views {
inline constexpr /* unspecified */ stride = /* unspecified */;
}
(since C++23)
Call signature
template< ranges::viewable_range R >
constexpr ranges::view auto stride( R&& r, ranges::range_difference_t<R> n );
(since C++23)
template< class DifferenceType >
constexpr /*range adaptor closure*/ stride( DifferenceType&& n );
(since C++23)
Helper templates
Feature-test macro Value Std Feature __cpp_lib_ranges_stride 202207L (C++23) std::ranges::stride_view
#include <algorithm>
#include <iostream>
#include <ranges>
#include <string_view>
using namespace std::literals;
void print(std::ranges::viewable_range auto&& v, std::string_view separator = " ")
{
for (auto const& x : v)
std::cout << x << separator;
std::cout << '\n';
}
int main()
{
print(std::views::iota(1, 13) | std::views::stride(3));
print(std::views::iota(1, 13) | std::views::stride(3) | std::views::reverse);
print(std::views::iota(1, 13) | std::views::reverse | std::views::stride(3));
print("0x0!133713337*x//42/A$@"sv | std::views::stride(0B11) |
std::views::transform([](char O) -> char { return 0100 | O; }),
"");
}
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.