diff --git a/inferno/src/inferno/singleton.h b/inferno/src/inferno/singleton.h new file mode 100644 index 0000000..568f3dc --- /dev/null +++ b/inferno/src/inferno/singleton.h @@ -0,0 +1,31 @@ +#ifndef SINGLETON_H +#define SINGLETON_H + +#include // std::unique_ptr + +namespace Inferno { + + template + class Singleton { + public: + static inline T& the() { + static const std::unique_ptr instance { new T { s {} } }; + return *instance; + } + + // Remove copy constructor and copy assignment operator + Singleton(const Singleton&) = delete; + Singleton& operator=(const Singleton&) = delete; + Singleton(Singleton&&) = delete; + Singleton& operator=(Singleton&&) = delete; + + protected: + Singleton() {} + + // Constructor token + struct s {}; + }; + +} // namespace Inferno + +#endif // SINGLETON_H