diff options
Diffstat (limited to 'AK/Singleton.h')
-rw-r--r-- | AK/Singleton.h | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/AK/Singleton.h b/AK/Singleton.h index 0abfa2b277..57962e3176 100644 --- a/AK/Singleton.h +++ b/AK/Singleton.h @@ -39,18 +39,9 @@ namespace AK { -template<typename T> -struct SingletonInstanceCreator { - static T* create() - { - return new T(); - } -}; - -template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create> +template<typename T, T* (*InitFunction)()> class Singleton { AK_MAKE_NONCOPYABLE(Singleton); - AK_MAKE_NONMOVABLE(Singleton); public: Singleton() = default; @@ -119,4 +110,18 @@ private: mutable T* m_obj { nullptr }; // atomic }; +template<typename T> +struct SingletonInstanceCreator { + static T* create() + { + return new T(); + } +}; + +template<typename T> +inline Singleton<T, SingletonInstanceCreator<T>::create> make_singleton() +{ + return Singleton<T, SingletonInstanceCreator<T>::create>(); +} + } |