liveBook · Manning

Ranges API

As explained in Learn C++ by Example

<ranges> is the C++ standard library header that declares ranges, views, and range adaptors.

The <ranges> header provides C++ ranges, views, and range adaptors for processing containers without manually tracking iterator endpoints. A view can filter or transform elements while leaving the underlying container untouched. section 2.3.4

Use std::ranges::views with the pipe operator to make a sequence of operations readable. For example, drop_while skips initial values below 3, while filter can expose negative values for a simple validation check. section 2.3.4

Filtering a row

auto negative = [](int x) { return x < 0; }; auto negatives = row | std::views::filter(negative); assert(negatives.empty()); This checks that a generated row contains no negative numbers without maintaining iterator positions. section 2.3.4

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

Apply drop_while with a pipe to express a readable range-processing step. section 2.3.4

How Learn C++ by Example covers it

How deep it goes
Demonstrates drop_while, filter, pipe chaining, and validation, but does not develop adaptor internals.
Examples
Shows vector filtering, dropping values below three, checking nonnegative rows, and comparing iterator-based removal.
What it assumes
Assumes containers, iterators, lambdas, and range-based loops while contrasting them with ranges-based algorithms.
What you can do after
Apply it via std::views to compose readable filtering and skipping operations over containers.
How it connects
Connects containers, iterators, range-based for loops, lambdas, filters, and standard algorithms.

Also explained in

Compare how 2 books explain ranges API →

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.