The Meyers Singleton depends on the fact that local static variable initialization is atomic.
I'm building something similar but I want the singleton to actually be one of a number of derived types. The base class getInstance()
method should call a factory that will return the appropriate type.
My first idea is
static Foo *instance = FooFactory(...);
8.5p2 of N3337 seems to indicate that this is strictly initialization and not initialization and assignment and I interpret that to mean the entire statement is atomic. Is this correct?
If not would the statement
static Foo *instance(FooFactory(...));
be different?
Edit 8.5.2 -> 8.5.p2