mirror of
https://gitlab.com/hashborgir/d2tweaks-rnd2k.git
synced 2024-12-02 21:55:58 +00:00
21 lines
376 B
C
21 lines
376 B
C
|
#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;
|
||
|
}
|