C++ Logo

std-proposals

Advanced search

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

From: Chris Gary <cgary512_at_[hidden]>
Date: Wed, 1 Nov 2023 09:08:52 -0600
Got bit again by "not reply-all"...


> Why wouldn't you just write if( auto resVec = dbc.submit( query ); not
> resVec.empty()) ?
>

As a matter of preference, I try to keep conditionals as brief as possible
- or really just the idea of one outcome per line/statement.
The convention is "non-empty set == true".

On Wed, Nov 1, 2023 at 8:58 AM Edward Catmur <ecatmur_at_[hidden]> wrote:

>
>
> On Wed, 1 Nov 2023 at 09:34, Chris Gary via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> Frankly, I see nothing wrong with the idea. Its really the same as "0 !=
>> c.size()" or " ! c.empty()".
>> With, as Arthur pointed out, the benefit of being able to instantiate
>> something like a range in a conditional, just extended to containers:
>>
>> Ex:
>>
>> dlg.clearList();
>> if( auto resVec = dbc.submit( query ) )
>> {
>> dlg.populateList( resVec );
>> }
>>
>
> Why wouldn't you just write if( auto resVec = dbc.submit( query ); not
> resVec.empty()) ?
>
>
>> On Tue, Oct 31, 2023 at 7:54 PM Arthur O'Dwyer via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> https://quuxplusone.github.io/blog/2021/12/06/views-are-boolish/
>>>
>>> On Tue, Oct 31, 2023 at 9:45 PM Hewill Kang via Std-Proposals <
>>> std-proposals_at_[hidden]> wrote:
>>>
>>>> Ranges adaptors *do* provide (explicit) operator bool since they all
>>>> derived from ‘view_interface’.
>>>>
>>>> Olaf van der Spek via Std-Proposals <std-proposals_at_[hidden]>於
>>>> 2023年11月1日 週三,04:44寫道:
>>>>
>>>>> On Thu, Oct 19, 2023 at 12:06 PM Alex Rozenman via Std-Proposals
>>>>> <std-proposals_at_[hidden]> wrote:
>>>>> > In this message I would like to suggest to use of a bool casting
>>>>> operator as the most clean form of this function:
>>>>>
>>>>> Nice suggestion. ;)
>>>>>
>>>>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3509.htm
>>>>>
>>>>>
>>>>> --
>>>>> Olaf
>>>>> --
>>>>> Std-Proposals mailing list
>>>>> Std-Proposals_at_[hidden]
>>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>>>
>>>> --
>>>> Std-Proposals mailing list
>>>> Std-Proposals_at_[hidden]
>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>

Received on 2023-11-01 15:09:04