The ext::single wraps a type in a singleton-like style to provide an access to a global instance of the type from anywhere in a program. Yet, like in a singletons, the instance of the type is created only when required.
The oprator -> is used to access the instance of the type. It is not important if the ext::single is local, global or has a dynamic storage, it always points to one common instance of T.
template <typename T,
template <typename> class P = ext::single_destroyable_policy>
class ext::single {
public:
inline T * operator -> ();
};
template <typename T> class ext::single_destroyable_policy;
template <typename T> class ext::single_nondestroyed_policy;
#include <ext/c++>
// ...
// somewhere in project:
ext::single <app::log> () -> printf (/* ... */);
// ...
Note that the construction and destruction of the wrapped type are not thread-safe. The user may need to implement own operator new and operator delete to ensure thread-safety if required.
[index]