Audacity 3.2.0
Public Member Functions | List of all members
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer Struct Reference

Can guarantee that the global variable's lifetime encloses those of other objects of static duration. More...

#include <GlobalVariable.h>

Public Member Functions

 Initializer ()
 

Detailed Description

template<typename Tag, typename Type, auto initializer = nullptr, bool ScopedOnly = true>
struct GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer

Can guarantee that the global variable's lifetime encloses those of other objects of static duration.

This is like the "nifty counter" idiom. The guarantee is not automatic, but you can define a static instance in a multiply included header file, which creates multiple Initializers, but only one of them causes the initial construction of the variable.

This makes it safe for other calls to Get() to occur inside the bodies of both the constructor and destructor of another long-lived object. Such objects can be freely defined by other translation units that include the header with no extra effort.

Definition at line 117 of file GlobalVariable.h.

Constructor & Destructor Documentation

◆ Initializer()

template<typename Tag , typename Type , auto initializer = nullptr, bool ScopedOnly = true>
GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer::Initializer ( )
inline

Definition at line 117 of file GlobalVariable.h.

117{ Initializer() { Instance(); } };
static mutable_type & Instance()
Generate the static variable.

References GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer::Initializer(), and GlobalVariable< Tag, Type, initializer, ScopedOnly >::Instance().

Referenced by GlobalVariable< Tag, Type, initializer, ScopedOnly >::Initializer::Initializer().

Here is the call graph for this function:
Here is the caller graph for this function:

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