>> 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@lists.isocpp.org> 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals