C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::expected

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 30 Aug 2025 16:56:15 +0100
On Sat, 30 Aug 2025, 14:58 Lénárd Szolnoki via Std-Proposals, <
std-proposals_at_[hidden]> wrote:

>
>
> 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


Yeah, you can't add that to std::expected, it's a language feature.

Received on 2025-08-30 15:56:38