C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 16 Jan 2026 08:58:39 +0000
On Fri, Jan 16, 2026 at 6:11 AM Simon Schröder wrote:
>
> In order for ‘return if’ to work with std::expected it would
> have to look even differently because it would have to call
> operator* (dereference operator) to return the result.


You've already seen me insert a unary operator between the "return"
and the "if" as follows:

    return ! if CalleeFunction();

In your case, using 'std::unexpected', the unary operator you desire
is '*' as follows:

    return * if CalleeFunction();

Oh and just as an aside . . . I personally have never used
'std::unexpected'. Of course there are really suitable uses for it,
but personally I'm fine with having one 'bad value' or 'absent value'
or 'unused value' among the data. If I had 3 or 4 or 5 bad values then
yeah maybe I'd go for 'std::unexpected' -- but for the vast majority
of problems it's just overkill.

Received on 2026-01-16 08:57:31