C++ Standard Views
summary
C++20/23 ranges views come with concrete pitfalls: some views cache begin which makes repeat iteration cheap but causes surprising const and lifetime errors, filter can produce undefined behavior when an element is modified to fail its predicate, and const propagation differs between lvalue and rvalue ranges. Practical fixes shown: use std::ranges::subrange, forwarding references, take-by-value for views, or copy views; a small prototype "Bell views" implements always-propagate const and avoids caching to restore predictable semantics.
AI-written summary · about
chapters (10)
- 0:00C++20 views intro
- 7:57How views work internally
- 14:02API: views vs containers
- 27:31Performance of view ops
- 38:49Pipe drop compile fail
- 51:27Undefined behavior with filter
- 1:01:21Modifying via zip views
- 1:15:37Broken principles in views
- 1:23:26Bell views proposal
- 1:34:13Final advice on views
related talks
01h 06mC++20 Ranges in Practice
01h 28mUnderstanding the Filter View to Use It Right
01h 02mC++20 Ranges in Practice
01h 01mAn Overview of Standard Ranges
01h 34mAn Overview of Standard Ranges
01h 01mFrom STL to Ranges: Using Ranges Effectively
57mRange Algorithms, Views and Actions: A Comprehensive Guide
56mWhat a View! Building Your Own (Lazy) Range Adaptors (part 2 of 2)
