OpenGTA/replaceLoki/Singleton.h

32 lines
464 B
C
Raw Normal View History

2018-09-23 05:57:34 +00:00
#ifndef SINGLETON_H_INCLUDED
#define SINGLETON_H_INCLUDED
#include <memory>
#include <cassert>
#include <thread>
#include <mutex>
namespace Loki
{
template <typename T>
struct SingletonHolder
{
static T& Instance()
{
static std::once_flag onceFlag;
static std::unique_ptr<T> singleton;
std::call_once(onceFlag,
[] {
singleton = std::make_unique<T>();
});
return *singleton.get();
}
};
}
#endif