C++ Logo

std-proposals

Advanced search

Re: Initialisers in ternary operators

From: Jorg Brown <jorg.brown_at_[hidden]>
Date: Sat, 12 Sep 2020 18:15:03 -0700
>> return (*auto It = Cont.find(42);* It == Cont.end()) ? 0 : It->second;

This is easy to rewrite currently, and it's not even more characters:

=> *auto It = Cont.find(42);* return (It == Cont.end()) ? 0 : It->second;

Or, if you really need It to be in its own scope, perhaps because of some
other It:

=> { *auto It = *Cont.find*(42)**;* return (It == Cont.end()) ? 0 :
It->second; }

And that's on top of all the lambda responses already on this thread.

On Thu, Sep 10, 2020 at 1:37 PM Dmitry Dmitry via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi,
>
> Since C++17 we can have init-statements in if:
> if (*char buf[10];* std::fgets(buf, 10, stdin)) { m[0] += buf; }
>
> That is excellent. But what about ternary operators (?:)?
> It seems I cannot write something like this now:
> return (*auto It = Cont.find(42);* It == Cont.end()) ? 0 : It->second;
>
> Is it deliberate?
> Are there any objections?
> What do you think?
>
> --
> Dmitry
> *Sent from gmail*
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-09-12 20:15:18