From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2025-06-12 08:24:37


Am 11.06.25 um 17:20 schrieb Andrey Semashev via Boost:
> On 11 Jun 2025 17:47, Ivan Matek wrote:
>> I agree with your concern about readability, but would strong typedef
>> work here?
>> I am not an atomic expert, but it seems wrapping uint32_t in a simple
>> struct does not destroy lockfree property of atomic.
>>
>> https://godbolt.org/z/WfGx76vxo <https://godbolt.org/z/WfGx76vxo>
> It would work, but it also would not enable bitwise operations on the
> atomic. And regarding integers, we already have a strong typedef in the
> language, it is called enums. :)

I fully agree  with Andrey here: https://godbolt.org/z/4c5E53czz
Compares the 2 approaches and I very much like the enum approach which
does not pollute the global scope with constants that should be scoped
too but isn't possibly with the strong type.
See:

>    auto configuration = kUseSimd | kUsePrefetching;
>
>    auto config = ConfigEnum::UseSimd | ConfigEnum::UsePrefetching;

I'm using the 2nd approach in a couple of projects, usually with a macro
or trait to enable the bitwise operators.

As for atomic enums: I wouldn't expect too much there as e.g. `config |=
ConfigEnum::UseSimd` wouldn't be reliable for atomics without a
compare&swap.
You noted that already for "user-defined bitwise operators defined for
an enum,", so I guess you are aware of that already.