liveBook · Manning

Pipe operator

As explained in Learn C++ by Example

The pipe operator is the operator used in C++ ranges expressions to compose a range with a view adaptor or transformation.

The pipe operator composes a range with a view adaptor or transformation. In C++ ranges expressions, it lets each step follow the previous one, avoiding deeply nested calls and iterator bookkeeping. section 2.3.4

Skipping the first values

A vector can be passed through drop_while with `v | std::views::drop_while([](int i) { return i < 3; })`. Iterating over the result prints `3 4 5`. The same style can filter negative values from a row: `row | std::views::filter(negative)`. section 2.3.4

for (int n : v | std::views::drop_while([](int i) { return i < 3; })) {
   std::cout << n << ' ';
}

Compare the pipe form with the equivalent direct call to see how chained range operations become easier to read. section 2.3.4

How Learn C++ by Example covers it

How deep it goes
Explains practical syntax and readability benefits, but defers detailed operator and view implementation internals.
Examples
Uses vector values, drop_while output `3 4 5`, and filtering negative numbers from triangle rows.
What it assumes
Assumes containers and range iteration while introducing views as read-only container perspectives.
What you can do after
Apply it via std::views to write readable range pipelines without tracking iterator positions.
How it connects
Connects ranges with views, filters, drop_while, lambdas, and range-based for loops.

Also explained in

Compare how 6 books explain pipe operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.