Why atomic<T> Has No Constructors

Template class atomic<T> deliberately has no declared constructors, because examples like GetUniqueInteger in Chapter 8 are commonly required to work correctly even before all file-scope constructors have been called. If atomic<T> declared a constructor, a file-scope instance might be initialized after it had been referenced.

As for any C++ class with no declared constructors, an object X of type atomic<T> is automatically initialized to zero in the following contexts:

The code below illustrates these points.

atomic<int> x;  // zero-initialized because it is at file scope
 
class Foo {
    atomic<int> y;
    atomic<int> notzeroed;
    static atomic<int> z;
public:
    Foo() :
        y()     // zero-initializes y.
    {
        // notzeroed has unspecified value here.
    }
};
 
atomic<int> Foo::z; // zero-initialized because it is a static member