Easy Navigation
Loading...
Searching...
No Matches
Singleton< C > Class Template Reference

#include <Singleton.hpp>

Static Public Member Functions

template<typename ... Args>
static C & get (Args &&... args)
template<typename ... Args>
static C * getInstance (Args &&... args)
static void removeInstance ()
 Destroy the current instance, if any; the next getInstance()/get() call creates a fresh one.

Protected Member Functions

Singleton & operator= (const Singleton &)=delete
 Singleton ()=default
 Singleton (const Singleton &)=delete
 ~Singleton ()=default

Constructor & Destructor Documentation

◆ Singleton() [1/2]

template<class C>
Singleton ( )
protecteddefault

◆ ~Singleton()

template<class C>
~Singleton ( )
protecteddefault

◆ Singleton() [2/2]

template<class C>
Singleton ( const Singleton< C > & )
protecteddelete

Member Function Documentation

◆ get()

template<class C>
template<typename ... Args>
C & get ( Args &&... args)
static

◆ getInstance()

template<class C>
template<typename ... Args>
C * getInstance ( Args &&... args)
static

◆ operator=()

template<class C>
Singleton & operator= ( const Singleton< C > & )
protecteddelete

◆ removeInstance()

template<class C>
void removeInstance ( )
static

Destroy the current instance, if any; the next getInstance()/get() call creates a fresh one.

Warning
Only safe to call when no other thread may still be dereferencing a C* obtained from an earlier getInstance()/get() call – that pointer's lifetime is tied to the destroyed instance, and no amount of locking here can protect a caller who is already holding and using it (the lock only serializes this class's own instance_/mutex_ bookkeeping against concurrent getInstance()/ removeInstance() calls). Intended for sequential use, e.g. resetting singleton state between test cases, not for tearing down an instance while it may still be in use elsewhere.

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