std::expected - Monadic Extensions -- Bartlomiej Filipek
The new std::expected feature from C++23 not only offers a robust error-handling mechanism but also introduces functional programming techniques like chaining operations with and_then, transforming results with transform, and managing errors using or_else and transform_error. This article explores these features, demonstrating how they can streamline your code by reducing redundant error checks while elegantly managing success and error states. Stay tuned as we dive into practical examples and see how these techniques are applied in real-world projects.
std::expected - Monadic Extensions
by Bartlomiej Filipek
From the article:
std::expectedfrom C++23 not only serves as an error-handling mechanism but also introduces functional programming paradigms into the language. In this blog post, we’ll have a look at functional/monadic extensions ofstd::expected,which allow us to chain operations elegantly, handling errors at the same time. The techniques are very similar tostd::optionalextensions - see How to Use Monadic Operations for `std::optional` in C++23 - C++ Stories.
Here’s a brief overview of these functional capabilities:
and_then()
Theand_thenmember function enables chaining operations that might produce astd::expectedobject. It’s invoked when thestd::expectedobject holds a value and allows for seamless operation chaining without manual error checking after each step.

Registration is now open for CppCon 2024! The conference starts on September 15 and will be held
Managing stateful notifications is challenging when multiple requests arrive, and the goal is to only notify about the latest one. In the
Registration is now open for CppCon 2024! The conference starts on September 15 and will be held
Registration is now open for CppCon 2024! The conference starts on September 15 and will be held
You have probably written a class that prints a message in all its special member functions. And like me, you probably wrote it multiple times. I decided to write it well once and for all, and share it.
If you're writing C++, there's a good reason (maybe...) as to why you are. And probably, that reason is performance. So often when reading about the language you'll find all sorts of "performance tips and tricks" or "do this instead because it's more efficient". Sometimes you get a good explanation as to why you should. But more often than not, you won't find any hard numbers to back up that claim. I recently found a peculiar one, the
Registration is now open for CppCon 2024! The conference starts on September 15 and will be held