Created
September 2, 2021 14:12
-
-
Save ryutorion/c5bf99048105cda9e49201e0843d6c09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SINGLETON(klass) \ | |
private:\ | |
static inline klass * mpInstance = nullptr;\ | |
public:\ | |
template <class... Args>\ | |
static void createInstance(Args... args) noexcept\ | |
{\ | |
if(mpInstance == nullptr)\ | |
{\ | |
mpInstance = new klass(args...);\ | |
}\ | |
}\ | |
static void destroyInstance() noexcept\ | |
{\ | |
delete mpInstance;\ | |
mpInstance = nullptr;\ | |
}\ | |
static klass & instance() { return *mpInstance; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment