What you need to distinguish is the default initialization and zero initialization. I’ve blushed for a long time on this topic, and came to the conclusion that the standard implicitly requires that the atomic class act identically to structures when it comes to initialization.
The non-atomic base type must be trivially copied, and the atomic type must both support default initialization and statically statically with (and without) ATOMIC_VAR_INIT . No pure solutions that I could come up with are obtained using the internal structure or the derivation from the structure (I wrote an atomic implementation for my own RT-system).
Thus, the standard, if not required, at least directs the implementation strongly towards a solution where zero initialization does exactly what you want.
I made a Live Example that compares the following:
std::array<t, 2> default; std::array<t, 2> zero{}; std::array<t, 2> explicit{{{0},{0}}};
you'll see that zero initialization is identical to the explicit version, and gcc 6.3.0 is even more efficient.
Just to repeat, I do not think that the standard explicitly requires that zero initialization behave in this way, but, to my understanding, given what is defined, it must be.
source share