views::transform
C++23Apply a function to each element lazily.
Section hub
template< ranges::forward_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>
class split_view
: public ranges::view_interface<split_view<V, Pattern>>
(since C++20)
namespace views {
inline constexpr /* unspecified */ split = /* unspecified */;
}
(since C++20)
Call signature
template< ranges::viewable_range R, class Pattern >
requires /* see below */
constexpr ranges::view auto split( R&& r, Pattern&& pattern );
(since C++20)
template< class Pattern >
constexpr /* range adaptor closure */ split( Pattern&& pattern );
(since C++20)
Before P2210R2, split_view used a lazy mechanism for splitting, and thus could not keep the bidirectional, random access, or contiguous properties of the underlying view, or make the iterator type of the inner range same as that of the underlying view. Consequently, it is redesigned by P2210R2, and the lazy mechanism is moved to lazy_split_view.
The delimiter pattern generally should not be an ordinary string literal, as it will consider the null terminator to be necessary part of the delimiter; therefore, it is advisable to use a std::string_view literal instead.
#include <iomanip>
#include <iostream>
#include <ranges>
#include <string_view>
int main()
{
using std::operator""sv;
constexpr auto words{"Hello^_^C++^_^20^_^!"sv};
constexpr auto delim{"^_^"sv};
for (const auto word : std::views::split(words, delim))
// with string_view's C++23 range constructor:
std::cout << std::quoted(std::string_view(word)) << ' ';
std::cout << '\n';
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P2210R2 | C++20 | the old split_view was too lazy to be easily used | it is redesigned |
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.