Browse Source

Add singleton class

master
Riyyi 3 years ago
parent
commit
0cc22100e9
  1. 31
      inferno/src/inferno/singleton.h

31
inferno/src/inferno/singleton.h

@ -0,0 +1,31 @@
#ifndef SINGLETON_H
#define SINGLETON_H
#include <memory> // std::unique_ptr
namespace Inferno {
template<typename T>
class Singleton {
public:
static inline T& the() {
static const std::unique_ptr<T> 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
Loading…
Cancel
Save