C++ Logo

std-proposals

Advanced search

Re: [std-proposals] goto is not harmful (was: "once" keyword)

From: Federico Kircheis <federico_at_[hidden]>
Date: Wed, 24 May 2023 15:07:28 +0200
On Wed, May 24, 2023 at 03:02:56PM +0200, Alejandro Colomar via Std-Proposals wrote:
>On 5/24/23 14:57, LUCE Jean-Sébastien via Std-Proposals wrote:
>> Hello
>>
>> It is often useful to support multiple cancel conditions, like 'return' in
>> a function, but without having to isolate the code in such a function
>> (which is called from a single point).
>>
>> I'm used to write code like
>>
>> "
>> do {
>> if (Failed(Condition0))
>> break;
>> if (Failed(Condition1))
>> break;
>> Code_to_execute;
>> } while (0);
>> "
>
>The keyword exists, with a lovely name: goto
>
>```c
> if (failed(foo))
> goto x;
> if (failed(bar))
> goto x;
>
> baz();
>x:
>```
>
>
>
>[...]
>

Unfortunately it cannot be used in constexpr functions, maybe it is a
good time to lift that restriction...

Received on 2023-05-24 13:07:38