Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Created September 2, 2021 14:12
Show Gist options
  • Save ryutorion/c5bf99048105cda9e49201e0843d6c09 to your computer and use it in GitHub Desktop.
Save ryutorion/c5bf99048105cda9e49201e0843d6c09 to your computer and use it in GitHub Desktop.
#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