C++ Logo

std-proposals

Advanced search

Re: Yet another member function for std::map

From: Zhihao Yuan <zy_at_[hidden]>
Date: Wed, 28 Jul 2021 23:25:46 +0000
On Wednesday, July 28th, 2021 at 3:50 PM, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote:

>

> The difference in lines here is:
>

> Current:
>

> if(auto it = ages.find(name); it != ages.end())
>

> Proposed:
>

> if(auto age = ages.value_for(name)))
>

> So, you're talking about a difference of twelve characters. Not
>

> exactly what I would call "boilerplate".
>

> Also, it normalizes practice that is somewhat dubious. Indeed, we
>

> added special variable declaration syntax to C++17 specifically to
>

> discourage this kind of thing.

I wouldn't say the second form
is discouraged. But it does
have a drawback: what if you only
want the false branch?

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________

Received on 2021-07-28 18:25:54