C++ Logo

std-proposals

Advanced search

Re: Initialisers in ternary operators

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 10 Sep 2020 19:01:37 -0400
On Thu, Sep 10, 2020 at 6:28 PM Eyal Rozenberg via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> As a side-note I always wondered why statement-expressions weren't
> introduced instead of a bunch-of-initializer-capabilities.

Well, they were supposed to just be `if` and `switch` statements, the
two statements where an initializer was important. It was a focused
change for a specific problem; it wasn't supposed to metastasize.

The idea of proliferating statements into arbitrary expressions just
to contain the scope of some local seems... unpleasant. It'd be much
more reasonable if we just had a mechanism to explicitly end the scope
of an automatic variable.

Though you could just use `optional<T>` and reset it when you want to
terminate it.

Received on 2020-09-10 18:05:19