mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
39 lines
739 B
C++
39 lines
739 B
C++
#pragma once
|
|
|
|
/** Пример:
|
|
*
|
|
* class Derived : public Singleton<Derived>
|
|
* {
|
|
* friend class Singleton<Derived>;
|
|
* ...
|
|
* protected:
|
|
* Derived() {};
|
|
* };
|
|
*
|
|
* Или так:
|
|
*
|
|
* class Some
|
|
* {
|
|
* ...
|
|
* };
|
|
*
|
|
* class SomeSingleton : public Some, public Singleton<SomeSingleton> {}
|
|
*/
|
|
template<class Subject> class Singleton
|
|
{
|
|
public:
|
|
static Subject & instance()
|
|
{
|
|
/// Нормально при включенных thread safe statics в gcc (по-умолчанию).
|
|
static Subject instance;
|
|
return instance;
|
|
}
|
|
|
|
protected:
|
|
Singleton(){};
|
|
|
|
private:
|
|
Singleton(const Singleton&);
|
|
Singleton& operator=(const Singleton&);
|
|
};
|