Taming the Filter View in C++ Programming
Talkat CppCon 2024 · on Tuesday, 2024-09-17· at 16:45· Maple 3/4/5, 6700 North Gaylord Rockies Boulevard·
summary
Filter view behaves oddly in practice: begin can be linear and reverse can make iteration quadratic, transform-before-filter can re-evaluate values, caching makes a const filter fail to compile and causes data-race/UB when concurrent threads call begin/empty, and modifying elements so they no longer satisfy the predicate is undefined behavior at runtime. Practical fixes: put filters early, build views ad hoc or use subrange/all_view, prefer empty over size checks, avoid modifying through a filter, and prefer one-pass (input-iterator) use or taking views by value for safety.
AI-written summary · about
chapters (19)
- 0:00C++ filter view intro
- 1:10Basic filter view usage
- 3:04Composing views with pipes
- 5:37Range-based for with views
- 7:46Lazy evaluation in views
- 10:36Pull vs push model
- 13:48Performance impact of filter placement
- 15:19Containers vs views performance
- 18:55Cost of filter view ops
- 22:10Efficient iteration
- 26:47Reverse iteration
- 29:19Caching in views
- 33:14Reading filtered elements
- 36:26Thread safety issues
- 41:34Modifying elements
- 45:33Undefined behavior
- 52:36Filter view limitations
- 57:10Design alternatives
- 1:00:10Q&A
related talks
01h 04mRange adaptors - 5 years after C++20
01h 06mConquering C++20 Ranges
01h 04mEffective Ranges: A Tutorial for Using C++2x Ranges
01h 23mC++ Iteration Revisited 2024
01h 00mBack to Basics: (Range) Algorithms in C++
08mThe most important API design principle
28mDo Your Views Know Too Much?
01h 05mThe Imperatives Must Go!
