Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Singleton Class Reference

A minimal singleton class implementation. More...

#include <ahSingleton.H>

Public Member Functions

Deleted copy and move operations
 Singleton (const Singleton &)=delete
 
 Singleton (Singleton &&)=delete
 
Singletonoperator= (const Singleton &)=delete
 
Singletonoperator= (Singleton &&)=delete
 

Static Public Member Functions

static Singletonget_instance () noexcept
 Returns the unique instance of the Singleton.
 

Private Member Functions

 Singleton ()=default
 Private constructor to prevent direct instantiation.
 

Detailed Description

A minimal singleton class implementation.

This class demonstrates the Meyers singleton pattern and can be used directly when a simple singleton with no additional state or behavior is needed.

For singletons with custom state or behavior, prefer using the Make_Singleton macro on your own class.

Example

assert(&s1 == &s2); // Same instance
A minimal singleton class implementation.
static Singleton & get_instance() noexcept
Returns the unique instance of the Singleton.

Thread Safety

Thread-safe initialization is guaranteed by the C++11 standard for function-local static variables.

See also
Make_Singleton

Definition at line 177 of file ahSingleton.H.

Constructor & Destructor Documentation

◆ Singleton() [1/3]

Singleton::Singleton ( const Singleton )
delete

◆ Singleton() [2/3]

Singleton::Singleton ( Singleton &&  )
delete

◆ Singleton() [3/3]

Singleton::Singleton ( )
privatedefault

Private constructor to prevent direct instantiation.

Member Function Documentation

◆ get_instance()

static Singleton & Singleton::get_instance ( )
inlinestaticnoexcept

Returns the unique instance of the Singleton.

The instance is created on the first call (lazy initialization) and the same instance is returned on all subsequent calls.

Returns
Reference to the singleton instance.
Note
Thread-safe: initialization is guaranteed to be thread-safe by the C++11 standard (function-local static).

Definition at line 191 of file ahSingleton.H.

Referenced by TEST(), and TEST().

◆ operator=() [1/2]

Singleton & Singleton::operator= ( const Singleton )
delete

◆ operator=() [2/2]

Singleton & Singleton::operator= ( Singleton &&  )
delete

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