C++ Logo

std-proposals

Advanced search

Re: [std-proposals] "once" keyword

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Wed, 24 May 2023 18:02:18 +0500
> 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);
> "

 if (Failed(Condition0)) goto skip_Code_to_execute;
 if (Failed(Condition1)) goto skip_Code_to_execute;

 Code_to_execute;

skip_Code_to_execute:
 ...



One level of indentation less than with `do { } while (0)`/`once` blocks

Received on 2023-05-24 13:02:24