views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::forward_range V, std::size_t N >
requires ranges::view<V> && (N > 0)
class adjacent_view
: public ranges::view_interface<adjacent_view<V, N>>
(since C++23)
namespace views {
template< std::size_t N >
constexpr /* unspecified */ adjacent = /* unspecified */ ;
}
(since C++23)
namespace views {
inline constexpr auto pairwise = adjacent<2>;
}
(since C++23)
Call signature
template< ranges::viewable_range R >
requires /* see below */
constexpr ranges::view auto adjacent<N>( R&& r );
(since C++23)
views::adjacent only accepts forward ranges even when N is 0.
There are similarities between ranges::adjacent_view and ranges::slide_view:
The following table shows the differences between these adaptors:
#include <array>
#include <format>
#include <iostream>
#include <ranges>
#include <tuple>
int main()
{
constexpr std::array v{1, 2, 3, 4, 5, 6};
std::cout << "v = [1 2 3 4 5 6]\n";
for (int i{}; std::tuple t : v | std::views::adjacent<3>)
{
auto [t0, t1, t2] = t;
std::cout << std::format("e = {:<{}}[{} {} {}]\n", "", 2 * i++, t0, t1, t2);
}
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 4098 | C++23 | views::adjacent<0> used to accept input-only ranges | made rejected |
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.