1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +00:00

AK: Get rid of make_singleton function

Just default the InitFunction template argument.
This commit is contained in:
Tom 2020-08-21 11:39:30 -06:00 committed by Andreas Kling
parent 8a75e0b892
commit 5a98e329d1
31 changed files with 42 additions and 46 deletions

View file

@ -39,9 +39,18 @@
namespace AK {
template<typename T, T* (*InitFunction)()>
template<typename T>
struct SingletonInstanceCreator {
static T* create()
{
return new T();
}
};
template<typename T, T* (*InitFunction)() = SingletonInstanceCreator<T>::create>
class Singleton {
AK_MAKE_NONCOPYABLE(Singleton);
AK_MAKE_NONMOVABLE(Singleton);
public:
Singleton() = default;
@ -110,18 +119,4 @@ 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>();
}
}