#include <mutex>
#include <memory>
template<class T>
class KSingleton
{
public:
static std::shared_ptr<T> &Instance()
{
std::call_once(m_oc, Init);
return m_instance;
}
private:
KSingleton()=delete;
~KSingleton()=delete;
static void Init()
{
m_instance = std::shared_ptr<T>(new T());
}
private:
static std::once_flag m_oc;
static std::shared_ptr<T> m_instance;
};
template<class T>
std::once_flag KSingleton<T>::m_oc;
template<class T>
std::shared_ptr<T> KSingleton<T>::m_instance = nullptr;