mirror of
https://gitlab.com/hashborgir/d2tweaks-rnd2k.git
synced 2025-12-15 11:41:35 -06:00
Initial commit
This commit is contained in:
21
include/fw/singleton.h
Normal file
21
include/fw/singleton.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
template<typename T>
|
||||
class singleton {
|
||||
public:
|
||||
static T& instance();
|
||||
|
||||
singleton(const singleton&) = delete;
|
||||
singleton& operator= (singleton) = delete;
|
||||
|
||||
protected:
|
||||
struct token {};
|
||||
singleton() = default;
|
||||
};
|
||||
|
||||
#include <memory>
|
||||
template<typename T>
|
||||
T& singleton<T>::instance() {
|
||||
static const std::unique_ptr<T> instance{ new T{token{}} };
|
||||
return *instance;
|
||||
}
|
||||
Reference in New Issue
Block a user