C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: David Brown <david.brown_at_[hidden]>
Date: Mon, 12 Jan 2026 10:52:56 +0100
On 12/01/2026 10:25, Muhammad via Std-Proposals wrote:
> What about the following syntax
>
> return <expression> if <condition>;
>
> it should give the same effect and it syntax is more concise.
>

And how is that better than :

 if <condition> return <expression>;

?

It has the disadvantages of being backwards in its operation (since
"condition" needs to be evaluated and checked before the return), and it
means you can't use an identifier declared in the "if" as part of the
return expression.

The "try?" operator from P2561 is quite specific, usable with particular
types like std::expected<> and std::optional<>. And the point of it is
that you wouldn't have to use an explicit "return" at all.

Received on 2026-01-12 09:53:03