C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Filip <fph2137_at_[hidden]>
Date: Mon, 12 Jan 2026 12:21:43 +0100
I love the idea of return if and wanted to propose something like this before!

Maybe instead of using keywords as modifiers we should talk about introducing a new keyword return_if which would do the early return.

Cheers, Filip

> Wiadomość napisana przez David Brown via Std-Proposals <std-proposals_at_[hidden]> w dniu 12 sty 2026, o godz. 10:53:
>
> 
>
>> 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.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-01-12 11:21:58