C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Bool casting operator to check if a container not empty

From: Federico Kircheis <federico_at_[hidden]>
Date: Sun, 22 Oct 2023 05:23:25 +0000
On 22 October 2023 02:29:15 UTC, Tony V E via Std-Proposals <std-proposals_at_[hidden]> wrote:
>On Thu, Oct 19, 2023 at 1:26 PM Federico Kircheis via Std-Proposals <
>std-proposals_at_[hidden]> wrote:
>
>>
>>
>> Also I might not sure if the feature is worth it.
>> Unless one wants to get the first element (or an element in a specific
>> position), working with empty and non-empty containers normally does not
>> require special handling.
>>
>
>Yep!
>Sadly I often see code like:
>
>
>if (v.empty()) // unnecessary check for empty
> return 0;
>
>int answer = 0;
>for (auto e : v)
> answer += ....
>
>return answer;
>
>

At least it is possible to grep for empty and size...

Received on 2023-10-22 05:23:30