Library/C++/Creating a Singleton using C++0x

Overview
A is a common, well-known. This article briefly explains a generic way to make a class into a Singleton using classes, , and a helper method.

The basic idea is this:
 * Create a global weak_ptr<> to store a reference to the Singleton object
 * Add an acquire method to the class that will create this Singleton on the first call
 * Use std::shared_ptr<> to automatically ensure the Singleton is destroyed when the last reference is gone
 * Ensure the Singleton constructor and destructor are private to enforce correct usage

Implementation
In your singleton class:
 * 1) Add a public acquire method that calls a template function helper (will be shown in a moment). This must return a std::shared_ptr<> for the automatic release to occur properly.
 * 2) Add friend declaration to the template function to ensure only it has access to the protected constructor and destructor
 * 3) Add protected/private static singleton object as a std::weak_ptr<>
 * 4) Add protected/private constructor / destructor declarations

That is all that is required for each Singleton class. Now for the shared acquireSingleton template which does most of the work.

Make note of the following:
 * A DeleteFunctor object is used so that only acquireSingleton must be made a friend; otherwise shared_ptr itself would have to be a friend
 * This method is completely templatized so the creation-on-first-acquisition logic does not require duplication between classes