Advanced Ranges and Views

Advanced Ranges and Views

Lazy pipelines, projections, and view-oriented design beyond basic filter/transform examples.

Advanced Ranges and Views

Build lazy pipelines

auto top_scores = scores
    | std::views::filter([](int score) { return score >= 90; })
    | std::views::transform([](int score) { return score / 10; })
    | std::views::take(5);

Views are lazy and usually cheap to compose.

Projections with algorithms

std::ranges::sort(users, std::greater<>{}, &User::score);

Use projections to avoid small one-off lambdas when sorting or searching by a member.

Views are borrowed, not owned

Useful adaptors

Practical guidance