C++ Logo

std-proposals

Advanced search

Re: Initial Idea of Indirect If Statement

From: Magnus Fromreide <magfr_at_[hidden]>
Date: Sun, 27 Oct 2019 08:23:59 +0100
On Sun, Oct 27, 2019 at 02:14:51AM +1000, Andrew Tomazos via Std-Proposals wrote:
> We propose a new variant of the if statement that fuses a condition
> declaration with an indirection in the true branch. We call it an
> 'indirect if statement'.
>
> An indirect if statement of the form:
>
> if (DECL : EXPR) X else Y;
>
> is equivalent to:
>
> {
> auto&& __c = EXPR;
> if (__c) {
> DECL = *__c;
> X;
> } else {
> Y; // noteworthy: DECL is not in scope here
> }
> }


Is there any use case for this beyond saving a few keystrokes?

What does this enable that you couldn't do before?

Why is this particular construct important enough to warrant language support?

> So for example:
>
> int* get();
> /*...*/
> }
>
> The motivation should be self-evident enough from the examples for this
> first note.

I suppose that the fact that I have to ask proves that the motivation ain't
self-evident from the examples so please spell it out.

/MF

> Initial thoughts appreciated.
> -Andrew.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2019-10-27 02:26:18