Utils::GuardedObject Class
template <typename T> class Utils::GuardedObjectThe GuardedObject class owns a heap-allocated object and deletes it when the shutdown guard is destroyed. More...
| Header: | #include <shutdownguard.h> |
Detailed Description
This is the preferred way to hold a process-lifetime singleton, as it avoids a manual shutdownGuard() connection. Typically used as a function-local static:
MyThing &myThing()
{
static GuardedObject<MyThing> theMyThing; // created on first use,
return *theMyThing; // deleted at shutdown
}
Construct it from constructor arguments (as above) or from an existing object pointer (GuardedObject<MyThing>{new MyThing(...)}).
See also Utils::shutdownGuard().