Boost logo

Boost :

Subject: Re: [boost] Review Request: Singularity
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-08-23 07:56:18


On 23/08/2011 07:05, Ben Robinson wrote:

> 1) Singleton does not give you control over the lifetime of the object.
> Your implementation, for example, uses a static instance of the object,
> which is notorious when there are multiple singletons of this type which
> depend upon each-other. Controlling initialization and teardown order is
> famously difficult. Singularity does not suffer from these lifetime issues.

It's a function-scope static.
The object will be constructed when instance is called for the first
time, which is good enough to control initialization order.

> 2) Singleton forces global access to the class through the ::instance()
> member. Sometimes this is what you want, other times it is not.

It is trivial to change it to be what you want, including calling
special constructors. It's five lines and easily changed to suit
whatever needs you may have, which is not the case of a library, even
with a policy-based design, which is more restrictive.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk