C++ › Ranges & Views

What does the pipe operator | do with ranges?

Intermediate

Answer

The | operator composes range adaptors into a pipeline, feeding the output of one view into the next, read left to right. It makes transformations readable, like Unix pipes: range | filter | transform | take. Each stage is a lazy view, so the whole pipeline evaluates on demand during iteration.
auto r = v | std::views::filter(isEven)
             | std::views::transform(square);
Real-world example A data pipeline reads as filter-then-transform via |, far clearer than nested algorithm calls.

Common follow-ups: How is the pipeline evaluated? | Why is | readable?