I l@ve RuBoard Previous Section Next Section

6.13 SingletonHolder Class Template Quick Facts

  • SingletonHolder's declaration is as follows:

    
    
    template <
    
    
       class T,
    
    
       template <class> class CreationPolicy = CreateUsingNew,
    
    
       template <class> class LifetimePolicy = DefaultLifetime,
    
    
       template <class> class ThreadingModel = SingleThreaded
    
    
    >
    
    
    class SingletonHolder;
    
    
    
  • You instantiate SingletonHolder by passing it your class as the first template parameter. You select design variations by combining the other four parameters. Example:

    
    
    class MyClass { ... };
    
    
    typedef Singleton<MyClass, CreateStatic>
    
    
       MySingleClass;
    
    
    
  • You must define the default constructor, or you must use a creator other than the stock implementations of the Creator policy.

  • The canned implementations of the three policies are described in Table 6.1. You can add your own policy classes as long as you respect the requirements.

    I l@ve RuBoard Previous Section Next Section