Wednesday
Room 2
11:40 - 12:40
(UTC+02)
Talk (60 min)
Five Issues with std::expected and How to Fix Them
std::expected is a powerful abstraction for error handling and chaining computations introduced in the C++ 23 standard. Even though this abstraction is relatively new in the C++ ecosystem, it already has several issues, particularly when used as the primary error-handling mechanism in large code bases.
This talk will focus on the most significant practical challenges faced when working with std::expected, providing insights into common pitfalls and offering potential solutions. While some of these challenges are addressed in separate libraries, others are not. Much of the functionality discussed in this talk is not available in the standard library. However, I’ll demonstrate real-world code samples and point to open-source helper utilities that address some of these gaps.
This talk will be useful for software engineers looking to understand the limitations of std::expected, explore possible workarounds, and even contribute to the evolution of this abstraction by submitting proposals for future improvements.
Preliminary outline
1. Briefly about std::expected
2. Issue #1: The same type of error and value are allowed
3. Issue #2: A can of worms: having monadic and regular interface altogether
4. Issue #3: No customisation points when a value or error cannot be accessed
5. Issue #4: No built-in back and front binders for arguments
6. Issue #5: Not enough monadic operations (an applicative-like functionality)
7. Bonus: generic unwrap (aka access value) mechanisms
8. Conclusions