mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 19:02:04 +00:00
86eb4d2d06
* - "Arcadia" is the name of Yandex's monorepo.
45 lines
779 B
C++
45 lines
779 B
C++
#pragma once
|
|
|
|
|
|
namespace ext
|
|
{
|
|
|
|
/** Example (1):
|
|
*
|
|
* class Derived : public ext::singleton<Derived>
|
|
* {
|
|
* friend class ext::singleton<Derived>;
|
|
* ...
|
|
* protected:
|
|
* Derived() {};
|
|
* };
|
|
*
|
|
* Example (2):
|
|
*
|
|
* class Some
|
|
* {
|
|
* ...
|
|
* };
|
|
*
|
|
* class SomeSingleton : public Some, public ext::singleton<SomeSingleton> {}
|
|
*/
|
|
template <typename T> class singleton
|
|
{
|
|
public:
|
|
static T & instance()
|
|
{
|
|
/// C++11 has thread safe statics. GCC and Clang have thread safe statics by default even before C++11.
|
|
static T instance;
|
|
return instance;
|
|
}
|
|
|
|
protected:
|
|
singleton() {};
|
|
|
|
private:
|
|
singleton(const singleton &);
|
|
singleton & operator=(const singleton &);
|
|
};
|
|
|
|
}
|