Documentation

template<typename Derived>
class TiledArray::Singleton< Derived >

Singleton base class To create a singleton class A do:

class A : Singleton<A> {
private:
friend class Singleton<A>;
A(...); // define (private) constructors
};

Here's how to use it:

A::set_instance(Args...); // this creates the first instance of A, if A is
not default-constructible, otherwise can skip this A& the_instance_ref =
A::get_instance(); // throws if the instance of A had not been created
A* the_instance_ptr = A::get_instance_ptr(); // returns nullptr if the
instance of A had not been created
// the instance of A will be destroyed with other static-linkage objects

Definition at line 55 of file singleton.h.

Static Public Member Functions

template<typename D = Derived>
static std::enable_if_t< Singleton< D >::derived_is_default_constructible, D & > get_instance ()
 
template<typename D = Derived>
static D & get_instance (std::enable_if_t<!Singleton< Derived >::derived_is_default_constructible > *=nullptr)
 
template<typename D = Derived>
static std::enable_if_t< Singleton< D >::derived_is_default_constructible, D * > get_instance_ptr ()
 
template<typename D = Derived>
static D * get_instance_ptr (std::enable_if_t<!Singleton< Derived >::derived_is_default_constructible > *=nullptr)
 
template<typename... Args>
static void set_instance (Args &&... args)
 

Protected Member Functions

template<typename... Args>
 Singleton (Args &&... args)
 

Static Protected Member Functions

static auto & instance_accessor ()
 

Constructor & Destructor Documentation

◆ Singleton()

template<typename Derived >
template<typename... Args>
TiledArray::Singleton< Derived >::Singleton ( Args &&...  args)
inlineprotected

Definition at line 128 of file singleton.h.

Member Function Documentation

◆ get_instance() [1/2]

template<typename Derived >
template<typename D = Derived>
static std::enable_if_t<Singleton<D>::derived_is_default_constructible, D&> TiledArray::Singleton< Derived >::get_instance ( )
inlinestatic
Returns
reference to the instance

Definition at line 70 of file singleton.h.

◆ get_instance() [2/2]

template<typename Derived >
template<typename D = Derived>
static D& TiledArray::Singleton< Derived >::get_instance ( std::enable_if_t<!Singleton< Derived >::derived_is_default_constructible > *  = nullptr)
inlinestatic
Returns
reference to the instance
Exceptions
std::logic_errorif the reference has not been contructed (because Derived is not default-constructible and set_instance() had not been called)

Definition at line 82 of file singleton.h.

◆ get_instance_ptr() [1/2]

template<typename Derived >
template<typename D = Derived>
static std::enable_if_t<Singleton<D>::derived_is_default_constructible, D*> TiledArray::Singleton< Derived >::get_instance_ptr ( )
inlinestatic
Returns
pointer to the instance, or nullptr if it has not yet been constructed

Definition at line 97 of file singleton.h.

◆ get_instance_ptr() [2/2]

template<typename Derived >
template<typename D = Derived>
static D* TiledArray::Singleton< Derived >::get_instance_ptr ( std::enable_if_t<!Singleton< Derived >::derived_is_default_constructible > *  = nullptr)
inlinestatic
Returns
pointer to the instance, or nullptr if it has not yet been constructed

Definition at line 107 of file singleton.h.

◆ instance_accessor()

template<typename Derived >
static auto& TiledArray::Singleton< Derived >::instance_accessor ( )
inlinestaticprotected

Definition at line 130 of file singleton.h.

Here is the caller graph for this function:

◆ set_instance()

template<typename Derived >
template<typename... Args>
static void TiledArray::Singleton< Derived >::set_instance ( Args &&...  args)
inlinestatic

Constructs the instance. This must be called if Derived is not default-constructible.

Template Parameters
Argsa parameter pack type
Parameters
argsa parameter pack

Definition at line 120 of file singleton.h.

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
Singleton(Args &&... args)
Definition: singleton.h:128