shadPS4/src/Util/Singleton.h
2023-05-23 07:48:25 +03:00

27 lines
No EOL
344 B
C++

#pragma once
#include <cstdlib>
#include <new>
template <class T>
class Singleton
{
public:
static T* Instance()
{
if (!m_instance)
{
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
new (m_instance) T;
}
return m_instance;
}
protected:
Singleton();
~Singleton();
private:
static inline T* m_instance = nullptr;
};