Best practice for singletons?

There are many ways to skin the singleton cat. In fact, boost itself sports several--some publicly exposed, some in "detail". I'm wondering if any one or two of these might be considered to be the current state-of-the-art with regard to implementing a singleton. I can certainly "roll my own" as I've done in the past, but if I can stand on the shoulders of giants and since I already have an accepted dependency on boost, I definitely prefer that. I do not wish to engage in any religious wars regarding singletons--I'm aware that they have their evils. Thanks much! -- Chris Cleeland

Hi, The singletons in boost are supposed to be only used by boost libraries. I dont know if it's your case but if it's not, you shouldn't try to use it. Someone proposed an alternative that might be more interesting, if it fits your need: http://comments.gmane.org/gmane.comp.lib.boost.devel/222463 Joël Lamotte

2012/4/11 Klaim - Joël Lamotte
Hi,
The singletons in boost are supposed to be only used by boost libraries. I dont know if it's your case but if it's not, you shouldn't try to use it.
There are a couple that are exposed in public interfaces. Specifically, I refer to the singleton in serialization as well as the singleton in exposed in pool. I understand that those in "detail" are hidden, but that would not prevent me from duplicating them in my own code if one particular implementation is considered a best-practice.
Someone proposed an alternative that might be more interesting, if it fits your need: http://comments.gmane.org/gmane.comp.lib.boost.devel/222463
Thanks for that reference! Singularity addresses one big issue I typically contend with regarding singletons--lifecycle--but the other cited issues (scope and initialization) are generally not issues for me. The notion of "singularity" being an orthogonal attribute to so many others. -- Chris Cleeland
participants (2)
-
Chris Cleeland
-
Klaim - Joël Lamotte