C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: David Brown <david.brown_at_[hidden]>
Date: Mon, 12 Jan 2026 13:50:18 +0100
On 12/01/2026 13:20, Thiago Macieira via Std-Proposals wrote:
> On Monday, 12 January 2026 03:27:56 Central Standard Time David Brown via Std-
> Proposals wrote:
>> There is also the issue of the order of actions. C++ is, at heart, an
>> imperative language - "do this, then do that." Check the condition,
>> then optionally return. Allowing an "if" statement to be tagged on to
>> the end of a "return" looks like the start of the slippery slope leading
>> to Perl...
>
> Then we'll also ask for "unless".
>
> return 0 unless foo();
>

How about a "having_first_done" keyword?

 printf(" world\n") having_first_done printf("Hello");

There are many times when it is useful to specify actions in a different
order than they should be executed, and there are plenty of existing
ways to write C++ where things happen in an order that is different from
the apparent reading order of statements. But I don't think readability
will be improved by something as clearly Yoda-speak as "return if".


> Do note you can write:
>
> foo() or die("error");
>
>

Received on 2026-01-12 12:50:23