Safe and Readable Code - Monadic Operations in C++23
summary
Shows how C++20/23 monadic operations make code clearer by using std::views::transform and std::views::join, returning errors with std::optional or std::expected, and wiring continuations with the cute library; demonstrates a custom pointer-monad and a writer-monad for lock-free tracing. Benchmarks on a pipeline that expands to ~250k items show views are 2–13× faster than naive container pipelines while a views+container combo can be ~38× slower, worst case ~6 ns/item. Highlights real pitfalls like dangling reference from lazy views and confusing auto return types.
AI-written summary · about
chapters (22)
- 0:00Introduction
- 1:14Traditional error handling problems
- 3:19Talk goals and focus
- 4:41Functors introduction
- 8:36Functors as transformations
- 9:38Functor rules
- 11:25Functional pipelines with views
- 13:53Key view characteristics
- 15:40Views pitfalls and best practices
- 17:27Callables in monadic ops
- 21:19Monads introduction
- 23:26Monadic pipelines for errors
- 25:34Pure functions benefits
- 33:05Error handling with optional/expected
- 36:42Chaining optional ops
- 40:35Advanced expected handling
- 44:31Optional first-success pipeline
- 47:21Debugging monadic compiler errors
- 50:36Custom monadic wrappers
- 56:38Combining monads
- 1:01:18Performance benchmarks
- 1:06:39Key takeaways and practical recommendations
related talks
01h 18mSafe and Readable C++ Code: Monadic Operations in C++23
01h 03mMonads in Modern C++
38mWhat's New In C++23
01h 02mC++20 - My Favourite Code Examples
01h 35mC++20 – My Favourite Code Examples
59mC++20 - My Favourite Code Examples
01h 09mThe Definitive Guide to Functional Programming in Cpp
05mPostmodern Meta C++
