C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::expected

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Sat, 30 Aug 2025 14:58:15 +0100
On 30 August 2025 13:47:36 BST, 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*?

https://wg21.link/P2561

>I think this is something that would greatly benefit the current
>*std::expected* implementation.
>
>Thanks in advance!
>

Received on 2025-08-30 13:58:23