C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 12 Jan 2026 14:06:29 +0100
Perhaps such a type could be created in a function:   evaluate(something(param)).try?;   With a user-defined evaluate() to have try return the result if trueish.   -----Ursprüngliche Nachricht----- Von:David Brown via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mo 12.01.2026 10:53 Betreff:Re: [std-proposals] return if An:std-proposals_at_[hidden]; CC:David Brown <david.brown_at_[hidden]>; 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 13:22:22