/* * singleton.h * * Created on: Sep 11, 2019 * Author: compi */ #ifndef SINGLETON_H_ #define SINGLETON_H_ #include template class Singleton { public: static T &Instance() { return *m_instance; } template static T &Instance(Args &&... args) { static T instance{ std::forward(args)... }; if(!m_instance) m_instance = &instance; return instance; } protected: Singleton() = default; Singleton(const Singleton &) = delete; Singleton &operator=(const Singleton &) = delete; virtual ~Singleton() = default; static T *m_instance; }; template T* Singleton::m_instance = nullptr; #endif /* SINGLETON_H_ */