25 lines
499 B
C
25 lines
499 B
C
|
#ifndef SINGLETON_H
|
|||
|
#define SINGLETON_H
|
|||
|
|
|||
|
#include <iostream>
|
|||
|
|
|||
|
template<typename T>
|
|||
|
class Singleton
|
|||
|
{
|
|||
|
public:
|
|||
|
static T* getInstance() noexcept(std::is_nothrow_constructible<T>::value)
|
|||
|
{
|
|||
|
static T instance{token()};
|
|||
|
return &instance;
|
|||
|
}
|
|||
|
virtual ~Singleton() =default;
|
|||
|
Singleton(const Singleton&)=delete;
|
|||
|
Singleton& operator =(const Singleton&)=delete;
|
|||
|
|
|||
|
protected:
|
|||
|
struct token{}; // helper class
|
|||
|
Singleton() noexcept=default;
|
|||
|
};
|
|||
|
|
|||
|
#endif // SINGLETON_H
|