d2tweaks-rnd2k/include/fw/singleton.h

21 lines
376 B
C
Raw Normal View History

2024-04-17 03:45:38 +00:00
#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;
}