singleton: add "maybe" pointer accessor

This commit is contained in:
Danny Robson 2020-09-11 13:35:51 +10:00
parent ca192ef4d8
commit 9153155076

View File

@ -71,15 +71,25 @@ namespace cruft {
} }
/// returns a reference to sole instantiated value /// Returns a reference to the instantiated value.
/// ///
/// `instantiate` must have already been called before `get` is called. /// `instantiate` must have already been called before `get` is called
/// otherwise the results are undefined.
static SelfT& static SelfT&
get (void) get (void)
{ {
CHECK (instance); CHECK (instance);
return *instance; return *instance;
} }
/// returns a pointer to the instantiated value if it exists, else we
/// return nullptr.
static SelfT*
maybe (void)
{
return instance;
}
}; };
}; };