24#ifndef quantlib_singleton_hpp
25#define quantlib_singleton_hpp
57 template <
class T,
class Global = std::
integral_constant<
bool, false> >
76#ifdef QL_ENABLE_SESSIONS
78#if (defined(__GNUC__) && !defined(__clang__)) && (((__GNUC__ == 8) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 8))
79#pragma message("Singleton::instance() is always compiled with `-O0` for versions of GCC below 8.4 when sessions are enabled.")
80#pragma message("This is to work around the following compiler bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91757")
81#pragma message("If possible, please update your compiler to a more recent version.")
82#pragma GCC push_options
83#pragma GCC optimize("-O0")
86 template <
class T,
class Global>
89 static T global_instance;
90 return global_instance;
92 thread_local static T local_instance;
93 return local_instance;
97#if (defined(__GNUC__) && !defined(__clang__)) && (((__GNUC__ == 8) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 8))
98#pragma GCC pop_options
103 template <
class T,
class Global>
Basic support for the singleton pattern.
Singleton(Singleton &&)=delete
Singleton(const Singleton &)=delete
Singleton & operator=(Singleton &&)=delete
static T & instance()
access to the unique instance
Singleton & operator=(const Singleton &)=delete