Files
ts-qt/modern-qt/utility/wrapper/singleton.hh
2025-10-20 00:32:01 +08:00

24 lines
460 B
C++

#pragma once
#include <memory>
namespace creeper::util {
template <typename T> class Singleton {
public:
static T& instance();
Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete;
protected:
struct token { };
Singleton() = default;
};
template <typename T> inline T& Singleton<T>::instance() {
static const std::unique_ptr<T> instance { new T { token {} } };
return *instance;
}
}