
On 1 February 2013 17:09, Alexander Stoyan <alexander.stoyan@gmail.com> wrote:
Hello Mathias,
I'm afraid you didn't get the point. Let me explain.
Without walking through the implementation in details, I didn't get it at first sight either.
The object will only be constructed when instance() is called
Technically, yes, the instance will be create once singleton::instance is called for the first time, but in order to make it constructed BEFORE main, singleton::instance has to be called during static data initialization, and static_init GUARANTIES that this static initialization will be performed before main WITH NO additional calls.
IMHO, the problem is, that you don't explain this important point in your blog (which I assume serves documentation purpose). The three crucial principles of the idea seem to be as follows: 1. singleton::instance is called during static initialisation. 2. static_unit guarantees that the requirement 1. is fulfilled. 3. static_unit realises the guarantee by... But, they don't stand out from your blog clearly. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net