detail/singleton.hpp provides a way to access a Singleton of a class type. This is not a general Singleton solution! It is restricted in that the class type must have a default constructor.
namespace details { namespace pool { template <typename T> class singleton_default { private: singleton_default(); public: typedef T object_type; static object_type & instance(); }; } // namespace pool } // namespace details
Symbol | Meaning |
---|---|
T | Any class with a non-throwing default constructor and non-throwing destructor |
Expression | Return Type | Assertion/Note/Pre/Post-Condition |
---|---|---|
singleton_default<T>::instance() | T & | Returns a reference to the singleton instance |
The singleton instance is guaranteed to be constructed before main() begins, and destructed after main() ends. Furthermore, it is guaranteed to be constructed before the first call to singleton_default<T>::instance() is complete (even if called before main() begins). Thus, if there are not multiple threads running except within main(), and if all access to the singleton is restricted by mutexes, then this guarantee allows a thread-safe singleton.
For details on how we provide the guarantees above, see the comments in the header file.
None.
This header may be replaced by a Boost singleton library.
Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)
This file can be redistributed and/or modified under the terms found in copyright.html
This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.