Subject: Re: [boost] Is there any interest in static constructors?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-02-01 17:57:08
On 01/02/2013 18:09, Alexander Stoyan wrote:
> There can many many different situation when you have to perform some
> additional data initialization and manipulation before creating singleton
> instance. Where would you put this code? Would you make singleton
> constructor or instance access method dependent on all this data when it
> naturally should not be?
What's the functional difference between putting it as a type list and
putting it as code?
> Anyway it doesn't solve the problem for the first call to a singleton if it
> has to be initialized before main.
If you want it to be initialized before main, then use global variables
or static members.
But then you have to make sure no threads exist prior to entering main.
Unlike for static variables in functions, global constructors are not
> but then you still need to refer to this variable from the
> code somewhere in order to make sure your compiler does not eliminate it
> due to optimization reasons, and this way you will introduce unnecessary
I have no idea what you're talking about. The compiler cannot remove
things if it changes observable behaviour, outside of a few situations
where copy constructors can be elided.
> 3. There is no construction recursion. If you did notice it somewhere,
> please point to exact place.
There is an "isinside" boolean.
> 4. Static data construction order is undefined by C++ standard fixing it
> requires either changing the standard or getting rid of class and global
> static data.
A given order can still be forced.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk