mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-24 04:15:01 +00:00
singleton: Use unique_ptr
This commit is contained in:
parent
7cbe7c762a
commit
f3504b2d25
3 changed files with 8 additions and 13 deletions
|
@ -1,24 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <memory>
|
||||
|
||||
template <class T>
|
||||
class singleton {
|
||||
public:
|
||||
public:
|
||||
static T* instance() {
|
||||
if (!m_instance) {
|
||||
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
|
||||
new (m_instance) T;
|
||||
m_instance = std::make_unique<T>();
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
singleton();
|
||||
~singleton();
|
||||
|
||||
private:
|
||||
static inline T* m_instance = nullptr;
|
||||
};
|
||||
private:
|
||||
static inline std::unique_ptr<T> m_instance{};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue