summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-22 16:34:14 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-22 16:34:14 +0200
commit68580d5a8d7adae1eebfa5a8c369d96a70d06bdb (patch)
tree83298fe2754fd1b2a2069d6d89efe5414b7d8b48 /AK
parent8a21491d863cd904aeed3b9bbf6d8bc8f537972c (diff)
downloadserenity-68580d5a8d7adae1eebfa5a8c369d96a70d06bdb.zip
Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d157a2db8379e0c97c6bdc1328027843.
Diffstat (limited to 'AK')
-rw-r--r--AK/FlyString.cpp2
-rw-r--r--AK/Singleton.h25
2 files changed, 16 insertions, 11 deletions
diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp
index 637ef9c596..e6e369c3f6 100644
--- a/AK/FlyString.cpp
+++ b/AK/FlyString.cpp
@@ -48,7 +48,7 @@ struct FlyStringImplTraits : public AK::Traits<StringImpl*> {
}
};
-static AK::Singleton<HashTable<StringImpl*, FlyStringImplTraits>> s_table;
+static auto s_table = make_singleton<HashTable<StringImpl*, FlyStringImplTraits>>();
static HashTable<StringImpl*, FlyStringImplTraits>& fly_impls()
{
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>();
+}
+
}