Boost logo

Boost :

Subject: [boost] Is there any interest in a base class which prevents construction during the static initialization phase?
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-06-12 19:51:04


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.

Usage would appear as follows:

#include <submission/nonstaticinitializable.hpp>
#include <boost/noncopyable.hpp>

    class Foo : private submission::nonstaticinitializable, private
        Foo() : nonstaticinitializable() {}
    }; // Foo

} // unnamed namespace

Foo fooThatWillAssert; // This instance asserts during static initialization

int main()
    nonstaticinitializable::enable_initialization(); // Indicates that
static initialization is complete.
    Foo foo; // This instance initializes successfully after static
    return 0;
} // main

What does Boost think about submission::nonstaticinitializable (I chose the
name to mirror noncopyable)?

Thank you,

Ben Robinson

Boost list run by bdawes at, gregod at, cpdaniel at, john at