3D
This commit is contained in:
@@ -4,13 +4,26 @@ template <typename Derived>
|
||||
class Singleton {
|
||||
public:
|
||||
static Derived* instance() {
|
||||
static Derived instance;
|
||||
return &instance;
|
||||
auto& value = storage();
|
||||
if (value == nullptr) {
|
||||
value = new Derived();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
static void destroy() {
|
||||
auto& value = storage();
|
||||
delete value;
|
||||
value = nullptr;
|
||||
}
|
||||
Singleton(const Singleton&) = delete;
|
||||
Singleton& operator=(const Singleton&) = delete;
|
||||
protected:
|
||||
Singleton() = default;
|
||||
~Singleton() = default;
|
||||
private:
|
||||
static Derived*& storage() {
|
||||
static Derived* value = nullptr;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
} // namespace Psc
|
||||
|
||||
Reference in New Issue
Block a user