emsApplication/applications/emsConfigurer/singleton.h

25 lines
499 B
C
Raw Normal View History

2024-09-12 16:23:44 +08:00
#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