views::transform
C++23Apply a function to each element lazily.
Section hub
template< std::movable Val, class CharT,
class Traits = std::char_traits<CharT> >
requires std::default_initializable<Val> &&
/*stream-extractable*/<Val, CharT, Traits>
class basic_istream_view
: public ranges::view_interface<basic_istream_view<Val, CharT, Traits>>
(since C++20)
Helper templates
template< class Val >
using istream_view = ranges::basic_istream_view<Val, char>;
(since C++20)
template< class Val >
using wistream_view = ranges::basic_istream_view<Val, wchar_t>;
(since C++20)
Customization point objects
namespace views {
template< class T >
constexpr /* unspecified */ istream = /* unspecified */;
}
(since C++20)
Helper concepts
template< class Val, class CharT, class Traits >
concept /*stream-extractable*/ =
requires(std::basic_istream<CharT, Traits>& is, Val& t) {
is >> t;
};
(exposition only*)
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <ranges>
#include <sstream>
#include <string>
int main()
{
auto words = std::istringstream{"today is yesterday’s tomorrow"};
for (const auto& s : std::views::istream<std::string>(words))
std::cout << std::quoted(s, '/') << ' ';
std::cout << '\n';
auto floats = std::istringstream{"1.1 2.2\t3.3\v4.4\f55\n66\r7.7 8.8"};
std::ranges::copy
(
std::views::istream<float>(floats),
std::ostream_iterator<float>{std::cout, ", "}
);
std::cout << '\n';
}
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3568 | C++20 | P2325R3 accidentally made the stored value default-initialized | restored to value-initialization |
| P2325R3 | C++20 | default constructor was provided asview must be default_initializable | removed along withthe requirement |
| P2432R1 | C++20 | ranges::istream_view was a function templateand did not follow the naming convention | made an alias template;customization point objects added |
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.