f407ve_freertos/components/f4ll_cpp/singleton.h
2021-10-31 00:33:00 +02:00

34 lines
598 B
C++

/*
* singleton.h
*
* Created on: Sep 11, 2019
* Author: compi
*/
#ifndef SINGLETON_H_
#define SINGLETON_H_
#include <utility>
namespace f4ll_cpp {
template<typename T> class Singleton {
public:
static T &Instance() {
static T instance;
return instance;
}
protected:
Singleton() = default;
Singleton(const Singleton &) = delete;
Singleton &operator=(const Singleton &) = delete;
virtual ~Singleton() = default;
static T *m_instance;
};
template<typename T> T* Singleton<T>::m_instance = nullptr;
} // f4ll_cpp
#endif /* SINGLETON_H_ */