CppCommon  1.0.4.1
C++ Common Library
singleton.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_UTILITY_SINGLETON_H
10 #define CPPCOMMON_UTILITY_SINGLETON_H
11 
12 namespace CppCommon {
13 
15 
45 template <typename T>
46 class Singleton
47 {
48  friend T;
49 
50 public:
51  Singleton(const Singleton&) = delete;
52  Singleton(Singleton&&) = delete;
53 
54  Singleton& operator=(const Singleton&) = delete;
55  Singleton& operator=(Singleton &&) = delete;
56 
58 
61  static T& GetInstance()
62  {
63  static T instance;
64  return instance;
65  }
66 
67 private:
68  Singleton() noexcept = default;
69  ~Singleton() noexcept = default;
70 };
71 
74 } // namespace CppCommon
75 
76 #endif // CPPCOMMON_UTILITY_SINGLETON_H
Singleton template base class.
Definition: singleton.h:47
Singleton(const Singleton &)=delete
Singleton & operator=(Singleton &&)=delete
static T & GetInstance()
Get singleton instance.
Definition: singleton.h:61
Singleton & operator=(const Singleton &)=delete
Singleton(Singleton &&)=delete
C++ Common project definitions.
Definition: token_bucket.h:15