Implementing Ranges and Views
summary
Explains how to implement new C++20/23 views by showing a working range adapter closure plus a CRTP-backed view that holds its input to avoid dangling iterators (naive subrange return causes UB), uses view_interface, deduction guides and views::all to choose owning vs ref views, and implements iterator behaviors (operator*, ++, sentinel comparisons) so filters, transforms and lazy set operations are single-pass. Case study builds lazy sorted-range adapters (merge, set_union/intersection) and shows std::generator as a simpler input-only alternative; implementations work but require careful lifetime and category handling.
AI-written summary · about
chapters (13)
- 0:00Introduction to ranges
- 1:44Terminology and foundations
- 5:02Views and range adaptors
- 9:06Composability examples
- 13:39Standard library views
- 18:22Writing custom adapters
- 26:56First adapter implementation
- 34:07Lifetime management and views::all
- 39:39Iterators and laziness
- 43:41Range categories and refinements
- 47:06Const-correctness and CPOs
- 52:53Case study: Sorted ranges
- 58:55Summary and conclusion
