GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
gmp::singleton< T, LongLifeTime > Class Template Reference

CRTP-based singleton helper with optional dead-reference recovery. More...

Detailed Description

template<typename T, bool LongLifeTime = false>
class gmp::singleton< T, LongLifeTime >

Derive a type T from singleton<T> to obtain a process-wide instance() accessor. The default specialization uses a function-local static object and provides the simplest singleton lifetime model. The LongLifeTime = true specialization keeps additional state so it can recreate the singleton after destruction if instance() is accessed again.

Template Parameters
TThe derived singleton type.
LongLifeTimeWhen false, use a function-local static instance. When true, enable dead-reference handling and recreation support.
Example
struct logger : gmp::singleton<logger> {
};
auto& log = logger::instance();
CRTP-based singleton helper with optional dead-reference recovery.
Definition singleton.hpp:54
#define GMP_DISABLE_CONSTRUCTION(Class)
Prevent direct public construction of a singleton-derived type.
consteval auto enum_values()
Get all enumerator values of an enumeration type at compile-time.
Definition meta.hpp:155
Since
version 1.2.0

Definition at line 54 of file singleton.hpp.


The documentation for this class was generated from the following file: