|
Boost : |
Subject: Re: [boost] Is there any interest in a base class which prevents construction during the static initialization phase?
From: Joshua Juran (jjuran_at_[hidden])
Date: 2011-06-12 23:14:30
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk