
On Jun 12, 2011, at 4:51 PM, Ben Robinson wrote:
Because the order of static initialization is undefined, numerous difficult to detect problems can arise when multiple objects are initialized during the static initialization phase. This base class would guarantee that a class will never be unintentionally constructed during static initialization. This is the same philosophy behind how boost::noncopyable guarantees that a class will never be unintentionally copied.
int main() { nonstaticinitializable::enable_initialization(); // Indicates that static initialization is complete. Foo foo; // This instance initializes successfully after static initialization. return 0; } // main
What does Boost think about submission::nonstaticinitializable (I chose the name to mirror noncopyable)?
The requirement to modify main() is sufficiently burdensome that I probably wouldn't use this technique, though I admit the failure mode is an assertion failure that's easy to fix. But also consider that the unit defining main() might be written in C. Josh