shadPS4/src/Emulator/Util/singleton.h

24 lines
398 B
C
Raw Normal View History

2023-10-13 08:40:59 +02:00
#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;
};