Skip to content

Latest commit

 

History

History
47 lines (31 loc) · 1.03 KB

File metadata and controls

47 lines (31 loc) · 1.03 KB

singleton

Back to API reference

Header

#include <ext/singleton>

Overview

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.

Key APIs

  • ext::singleton<T>::instance() returns the single static T instance.
  • Constructors/destructors are protected so derived classes control direct construction policy.
  • Copying is disabled where compiler support allows it.

Behavior Notes

  • The derived type generally declares singleton<T> as a friend when it wants private construction.
  • Initialization follows the platform/compiler static local initialization rules.

Requirements

  • GCC 8.3.0+
  • Clang 10.0+
  • Visual Studio 2008 SP1+

Examples

#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