You might want to have a look at std::expected’s monadic functions and_then, transform, or_else, and transform_error. These allow to chain function calls. It is not the regular imperative way of programming, but comes from the functional programming world.

On Aug 30, 2025, at 2:47 PM, Rhidian De Wit via Std-Proposals <std-proposals@lists.isocpp.org> wrote:


Hi all,

I've recently started using std::expected as I'm a fan of the idea of getting better error-types without needing to resort to integer-return types or exceptions.
However, I find std::expected quite cumbersome to use, primarily because I always need to check has_value() before safely accessing value()
Rust's Result (almost 1:1 with C++'s std::expected) type provides the ? operator to easily grab the contained value, or propagate the error to the callee if the Result type contains an error.
Is there a proposal to add similar functionality to C++'s std::expected? I think this is something that would greatly benefit the current std::expected implementation.

Thanks in advance!

--
Rhidian De Wit
Software Engineer - Barco
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals