views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::input_range V,
std::indirect_unary_predicate<ranges::iterator_t<V>> Pred >
requires ranges::view<V> && std::is_object_v<Pred>
class filter_view
: public ranges::view_interface<filter_view<V, Pred>>
(since C++20)
namespace views {
inline constexpr /* unspecified */ filter = /* unspecified */;
}
(since C++20)
Call signature
template< ranges::viewable_range R, class Pred >
requires /* see below */
constexpr ranges::view auto filter( R&& r, Pred&& pred );
(since C++20)
template< class Pred >
constexpr /* range adaptor closure */ filter( Pred&& pred );
(since C++20)
base: range to filterpred: predicate to filter out elements#include <iostream>
#include <ranges>
int main()
{
auto even = [](int i) { return 0 == i % 2; };
auto square = [](int i) { return i * i; };
for (int i : std::views::iota(0, 6)
| std::views::filter(even)
| std::views::transform(square))
std::cout << i << ' ';
std::cout << '\n';
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3714(P2711R1) | C++20 | the multi-parameter constructor was not explicit | made explicit |
| P2325R3 | C++20 | if Pred is not default_initializable, the default constructorconstructs a filter_view which does not contain a Pred | the filter_view is alsonot default_initializable |
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.