C++11 [atomics.types.generic]p7:
There shall be named types corresponding to the integral specializations of
atomic
, as specified in Table 145, and a named typeatomic_bool
corresponding to the specifiedatomic<bool>
. Each named type is a either typedef to the corresponding specialization or a base class of the corresponding specialization. If it is a base class, it shall support the same member functions as the corresponding specialization.
(emphasis added)
What's the rationale for letting std::atomic_char
not be identical to std::atomic<char>
, and so on for all the other types? What flexibility does this enable, and why is it useful? At first glance I don't understand why these wouldn't be required to be typedefs to std::atomic<T>
specializations directly.
Note that N2427 which proposed <atomic>
says that the typedefs are to specializations exactly, and not possibly to base classes.
It is probably there because someone already had an implementation of atomics using std::atomic_*
types as base classes and complained enough/provided a good argument towards this approach.
In MSVC such an implementation is suggested.
In this it is stated that
Remove the definional base-class relationship between atomic_.... named types and the corresponding specializations of the atomic template class. The base-class relationship is now implementation-dependent. This change ensures compatibility with C. Some member functions and operators, that were formerly inherited from the base class, must be hoisted from the named types to the specializations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With