24 lines
460 B
C++
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;
|
|
}
|
|
|
|
}
|