#include <ext/singleton>
Provides a small singleton<T> base class for types that want a process-local static instance. It is used internally by collection storage and safe-object tracing helpers.
ext::singleton<T>::instance()returns the single staticTinstance.- Constructors/destructors are protected so derived classes control direct construction policy.
- Copying is disabled where compiler support allows it.
- The derived type generally declares
singleton<T>as a friend when it wants private construction. - Initialization follows the platform/compiler static local initialization rules.
- GCC 8.3.0+
- Clang 10.0+
- Visual Studio 2008 SP1+
#include <ext/singleton>
class config : public ext::singleton<config> {
private:
friend ext::singleton<config>;
config() {}
public:
int value = 0;
};
config::instance().value = 42;
int value = config::instance().value;
// value == 42