2024-09-12 16:23:44 +08:00
|
|
|
|
#ifndef SINGLETON_H
|
|
|
|
|
#define SINGLETON_H
|
2024-10-12 14:00:37 +08:00
|
|
|
|
#pragma execution_character_set("utf-8")
|
2024-09-12 16:23:44 +08:00
|
|
|
|
|
|
|
|
|
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:
|
2024-10-12 14:00:37 +08:00
|
|
|
|
struct token {}; // helper class
|
2024-09-12 16:23:44 +08:00
|
|
|
|
Singleton() noexcept=default;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SINGLETON_H
|