How to rangify your code
summary
Claim: refactor loop-heavy C++ into composable range pipelines that are easier to read and reason about. Demonstrates concrete rewrites: small idioms (max, sliding mean, range generator), a matrix subtract mean implemented with a flat span and cycle view, and a full Jefferson seat allocation for 3 parties and 7 seats using cartesian_product then sort/take/count. Uses both std::ranges and range-v3, shows the exact views/algorithms used, and produces working, testable code examples with Compiler Explorer links.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 1:08Learning Resources
- 3:22Ranges Libraries
- 5:04What are Ranges?
- 8:53Simple Range Example
- 12:11Sliding Mean Example
- 16:34Matrix Manipulation
- 21:45Range Function Example
- 25:40Jefferson Method Algorithm
- 33:31Implementing complex algorithm
- 40:17Modernizing Algorithm Code
- 51:55Conclusion
related talks
42mAwaiting for the ranges: C++17
50mThinking Functionally in C++
01h 00mC++ Concepts and Ranges
58mFrom Iterators to Ranges: The Upcoming Evolution Of the STL
59mRange-based text formatting
01h 05mC++11 in the Wild: Techniques from a Real Codebase
55mMonadic Operations in C++23
01h 10mThe Three Little Dots and the Big Bad Lambdas
