mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-08 02:18:53 +00:00
26 lines
582 B
C++
26 lines
582 B
C++
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
namespace osquery {
|
|
|
|
// NOTE: T should have public or protected default ctor.
|
|
template <class T>
|
|
class Singleton : private T {
|
|
public:
|
|
static T& get() {
|
|
// C++11 guarantees that initialization of static local
|
|
// variables is thread-safe; Moreover, GCC started to
|
|
// provide the same guarantee long time ago.
|
|
// http://cppwisdom.quora.com/Singletons-are-easy
|
|
static Singleton<T> instance;
|
|
return instance;
|
|
}
|
|
|
|
private:
|
|
Singleton() {}
|
|
~Singleton() {}
|
|
};
|
|
|
|
} // namespace osquery
|