Semantics

Any class with a non-throwing default constructor and non-throwing destructor

Requirements satisfied by singleton_default<T>

Expression

Return Type

Assertion/Note/Pre/Post-Condition

singleton_default<T>::instance()

T &

Returns a reference to the singleton instance

Guarantees

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.

Details

For details on how we provide the guarantees above, see the comments in the header file.