On 2020-09-11 at 08:56, Richard Hodges via Std-Proposals wrote:
> GCC already has expression statements as an extension.
>
> I don't think it would hurt to standardise this into the language.
>
> https://godbolt.org/z/sb63dz
>
> e.g.:
> return ({
> auto i = m.find(x) ;
> i == m.end() ? nullptr : std::addressof(i->second);
> });
>
What's the supposed advantage of using a ternary operator here?
Only because it follows the style of the OP's initial use case/proposal.
Note that gcc/godbolt produces *exactly* the same machine code for
Completely understood. I don't think the proposal or GCC's expression statements are intended to do anything more than improve expressibility.
It seems to me that expression templates are merely an alternate shorthand for inline lambdas (that happen to also work in C).
if (auto i = m.find(x); i == m.end())
return nullptr;
else
return std::addressof(i->second);
>
> On Fri, 11 Sep 2020 at 09:19, Dmitry Dmitry via Std-Proposals
> <std-proposals@lists.isocpp.org <mailto:std-proposals@lists.isocpp.org>>
> wrote:
>
> Just write and use a find wrapper like these:
>
>
> It was just an example.
> If we start considering solving it via wrappers/helpers, then I
> would just create something like findOr(key, value) function.
>
> But, anyway, it seems that the idea is not worth it...
> Thanks for the feedback.
>
> --
> Dmitry
> *_Sent from gmail_*
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals