template<typename T>
class qpp::internal::Singleton< T >
Singleton policy class, used internally to implement the singleton pattern via CRTP (Curiously recurring template pattern)
To implement a singleton, derive your class from qpp::internal::Singleton, make qpp::internal::Singleton a friend of your class, then declare the constructor and destructor of your class as private. To get an instance, use the static member function qpp::internal::Singleton::get_instance() (qpp::internal::Singleton::get_thread_local_instance()), which returns a reference (thread_local reference) to your newly created singleton (thread-safe in C++11).
Example:
{
public:
private:
MySingleton()
{
}
~MySingleton()
{
}
};
MySingleton& mySingleton = MySingleton::get_instance();
thread_local MySingleton& tls = MySingleton::get_thread_local_instance();
- See also
- Code of qpp::Codes, qpp::Gates, qpp::Init, qpp::RandomDevices, qpp::States or qpp.h for real world examples of usage.