C++20 Ranges for Beginners
summary
C++20 ranges provide concrete tactics: use lazy views and the pipeline syntax to compose filter/transform/copy without copies, use projections to sort by a field, and use sentinels (e.g. unreachable_sentinel) for infinite sequences. Examples show views are cheap to create but lazy, begin can be cached causing surprising O(N) first-call costs, size() or index may be unavailable depending on the source container, and passing views by value can hide costly copies — prefer forwarding or overloads that accept views to avoid hidden allocations.
AI-written summary · about
chapters (20)
- 0:00Introduction to C++20 Ranges
- 1:10Why use Ranges?
- 2:39Range components and concepts
- 4:05Concepts in C++20
- 6:12Projections in sorting
- 7:19What are Views?
- 8:04Sentinels for infinite ranges
- 8:49First View example
- 9:32Transform and copy operations
- 10:17Chaining Views with pipe syntax
- 11:46View API differences
- 12:51Drop and size limitations
- 14:18View operations complexity
- 16:05Filter View limitations
- 18:33Common compilation errors
- 21:21Fixing const and reference issues
- 23:10Overload resolution solutions
- 24:18Sentinels explained
- 25:24Summary and use cases
- 26:51Q&A session
