#ifndef __OPENGLPLAYGROUND_SINGLETON_HH__ #define __OPENGLPLAYGROUND_SINGLETON_HH__ #include #include template class Singleton { public: static T& getInstance() { call_once(instance_flag, init); return *instance; } private: static std::unique_ptr instance; static std::once_flag instance_flag; static void init() { instance.reset(new T{}); } }; #endif