32 lines
464 B
C++
Executable File
32 lines
464 B
C++
Executable File
#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 |