Date: Sat, 30 Aug 2025 15:50:15 +0200
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_at_[hidden]> 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_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> On Aug 30, 2025, at 2:47 PM, Rhidian De Wit via Std-Proposals <std-proposals_at_[hidden]> 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_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-08-30 13:50:30