dune-common  2.2.1
singleton.hh
Go to the documentation of this file.
1 #ifndef DUNE_SINGLETON_HH
2 #define DUNE_SINGLETON_HH
3 
4 #include <memory>
5 
13 namespace Dune
14 {
50  template<class T>
51  class Singleton
52  {
54  static std::auto_ptr<T> instance_;
55  protected:
56  /* @brief Private constructor. */
59  Singleton(const Singleton&){}
62 
63  public:
68  static T& instance()
69  {
70  if(instance_.get() == 0)
71  instance_ = std::auto_ptr<T>(new T());
72  return *instance_;
73  }
74  };
75 
76  template<class T>
77  typename std::auto_ptr<T> Singleton<T>::instance_;
78 
79 } // namespace Dune
80 
81 #endif