Subject: Re: [boost] [atomic] (op)_and_test naming
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-01-25 13:06:14
On 01/25/18 14:32, Rob Stewart via Boost wrote:
> On January 24, 2018 6:32:01 PM EST, Gavin Lambert via Boost <boost_at_[hidden]> wrote:
>> On 25/01/2018 00:35, Andrey Semashev wrote:
>>> I would like to ask for the community opinion on the naming of the
>>> (op)_and_test functions that appeared in Boost.Atomic 1.66.
>> For clarity, I was the one who filed the issue mentioned in the OP.
>> My argument is the following:
>> * "if (x)" is true when x is an integer type that is nonzero. (And
>> this convention is often extended to non-integer types as well, for
>> suitable definitions of "zero".)
>> * "atomic_flag::test_and_set" is true when the flag was previously
>> * "atomic<T>::bit_test_and_set" is true when the bit was previously
>> * "atomic<T>::fetch_add" returns the value prior to the add, which is
>> true if nonzero due to the first rule.
>> It thus seems peculiar to have "atomic<>::add_and_test" return true
>> when the result is zero.
> Your consistency argument seems compelling, unless there are unidentified counterexamples.
I suppose, I can add one other example supporting that pattern:
Also, the standard includes wording such as "returns a value testable as
true" when it describes predicates that can be used with algorithms,
which means that the value can be contextually converted to bool (i.e.
true if not "zero").
It seems like the term "test" indeed implies "check if something is not