views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::view V >
class take_view
: public ranges::view_interface<take_view<V>>
(since C++20)
namespace views {
inline constexpr /* unspecified */ take = /* unspecified */;
}
(since C++20)
Call signature
template< ranges::viewable_range R >
requires /* see below */
constexpr ranges::view auto
take( R&& r, ranges::range_difference_t<R> count );
(since C++20)
template< class DifferenceType >
constexpr /* range adaptor closure */ take( DifferenceType&& count );
(since C++20)
#include <algorithm>
#include <iostream>
#include <ranges>
int main()
{
namespace views = std::views;
auto print = [](char x){ std::cout << x; };
for (const char nums[]{'1', '2', '3'};
int n : views::iota(0, 5))
{
std::cout << "take(" << n << "): ";
// safely takes only upto min(n, nums.size()) elements:
std::ranges::for_each(nums | views::take(n), print);
std::cout << '\n';
}
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3407 | C++20 | views::take sometimes failed toconstruct a sized random access range | the result type is adjusted sothat construction is always valid |
| LWG 3494 | C++20 | take_view was never a borrowed_range | it is a borrowed_range if its underlying view is |
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.