Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <cassert>
- template<class T>
- class singleton
- {
- singleton() {}
- ~singleton() { is_destructed = true; }
- static bool is_destructed;
- public:
- static T& instance()
- {
- assert(!is_destructed);
- (void)is_destructed; // prevent removing is_destructed in Release configuration
- static T inst;
- return inst;
- }
- static const T& const_instance() { return instance(); }
- };
- template<class T>
- bool singleton<T>::is_destructed = (singleton<T>::instance(), false); // force creating instance before main() is called
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement