views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::input_range V, ranges::forward_range Pattern >
requires ranges::view<V> &&
ranges::view<Pattern> &&
std::indirectly_comparable<ranges::iterator_t<V>,
ranges::iterator_t<Pattern>,
ranges::equal_to> &&
(ranges::forward_range<V> || /*tiny-range*/<Pattern>)
class lazy_split_view
: public ranges::view_interface<lazy_split_view<V, Pattern>>
(since C++20)
namespace views {
inline constexpr /* unspecified */ lazy_split = /* unspecified */;
}
(since C++20)
Call signature
template< ranges::viewable_range R, class Pattern >
requires /* see below */
constexpr ranges::view auto lazy_split( R&& r, Pattern&& pattern );
(since C++20)
template< class Pattern >
constexpr /* range adaptor closure */ lazy_split( Pattern&& pattern );
(since C++20)
Helper concepts
template< class R >
concept /*tiny-range*/ =
ranges::sized_range<R> &&
requires { /* is-statically-constexpr-sized */<R>; } &&
(std::remove_reference_t<R>::size() <= 1);
(exposition only*)
The name lazy_split_view is introduced by the post-C++20 defect report P2210R2. It has the same lazy mechanism as that of the old split_view before change.
#include <algorithm>
#include <iostream>
#include <ranges>
#include <string_view>
auto print = [](auto const& view)
{
// `view` is of std::views::lazy_split_view::__outer_iterator::value_type
for (std::cout << "{ "; const auto element : view)
std::cout << element << ' ';
std::cout << "} ";
};
int main()
{
constexpr static auto source = {0, 1, 0, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9};
constexpr int delimiter{0};
constexpr std::ranges::lazy_split_view outer_view{source, delimiter};
std::cout << "splits[" << std::ranges::distance(outer_view) << "]: ";
for (auto const& inner_view: outer_view)
print(inner_view);
constexpr std::string_view hello{"Hello C++ 20 !"};
std::cout << "\n" "substrings: ";
std::ranges::for_each(hello | std::views::lazy_split(' '), print);
constexpr std::string_view text{"Hello-+-C++-+-20-+-!"};
constexpr std::string_view delim{"-+-"};
std::cout << "\n" "substrings: ";
std::ranges::for_each(text | std::views::lazy_split(delim), print);
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P2210R2 | C++20 | the old split_view was too lazy to be easily used | moves its functionality to lazy_split_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.