C++ Logo

std-proposals

Advanced search

Re: [std-proposals] "once" keyword - RAII

From: Robin Rowe <robin.rowe_at_[hidden]>
Date: Wed, 24 May 2023 11:27:57 -0700
On 5/24/2023 5:57 AM, LUCE Jean-Sébastien via Std-Proposals wrote:

> do {
> if (Failed(Condition0))
> break;
> if (Failed(Condition1))
> break;
> Code_to_execute;
> } while (0);

In C++ we have destructors and RAII:

    if (object1.Failed(Condition0))
        return false;
    if (object2.Failed(Condition1))
        return false;

With the failed condition Code_to_execute being in the destructors of
object1 and object2, there's nothing to call explicitly when failed. If
a required condition fails, simply return.

Robin

Received on 2023-05-25 23:46:45