Boost logo

Boost :

Subject: [boost] [atomic] (op)_and_test naming
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-01-24 11:35:38


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.

As you probably know, 1.66 included a few new atomic operations, some of
which have the name (op)_and_test (e.g. add_and_test, sub_and_test,
etc.) These operations perform the (op) on the atomic value and test if
the result is zero, so that instead of this:

     if (a.fetch_sub(1) - 1 == 0)

one could write this:

     if (a.sub_and_test(1))

Also, the generated code for these operations can potentially be more

Recently I received this request:

which basically asks to change the result of the functions to the
opposite. I can see that the current naming could be confusing,
especially given that other operations like bit_test_and_set return the
previous bit value (i.e. true if the bit was 1). That would be a
breaking change, but the new operations were announced as experimental
in the release notes, so if there is consensus that the result should
indeed be changed, I'm ready to comply.

Another solution is change (op)_and_test naming to something else that
is more clear. In that case I could deprecate the (op)_and_test variants
and provide the functionality under the new names. I would welcome
suggestions for a better naming scheme, if you feel this is the right
way. My only ask is that the new names be concise, if possible.

Lastly, if you think the current naming is fine or there is another way
to resolve the confusion, please comment as well. I would appreciate
your opinion in any case.


Boost list run by bdawes at, gregod at, cpdaniel at, john at