Skip to content
Snippets Groups Projects
Commit 62f8065e authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Only test for destroyed status in debug builds

Refs #0
parent 1520c311
No related branches found
No related tags found
No related merge requests found
...@@ -67,15 +67,20 @@ template <typename T> struct CreateUsingNew { ...@@ -67,15 +67,20 @@ template <typename T> struct CreateUsingNew {
/// already exist /// already exist
/// Creation is done using the CreateUsingNew policy at the moment /// Creation is done using the CreateUsingNew policy at the moment
template <typename T> inline T &SingletonHolder<T>::Instance() { template <typename T> inline T &SingletonHolder<T>::Instance() {
// Local static instance initialized by an immediately invoked lambda. // Local static instance initialized by an immediately invoked lambda.
// A second nested lambda captures the singleton instance pointer // A second nested lambda captures the singleton instance pointer
// and forms the deleter function that is registered with // and forms the deleter function that is registered with
// the atexit deleters. // the atexit deleters.
#ifndef NDEBUG
static bool destroyed(false); static bool destroyed(false);
#endif
static T *instance = [] { static T *instance = [] {
auto *singleton = CreateUsingNew<T>::create(); auto *singleton = CreateUsingNew<T>::create();
deleteOnExit(deleter_t([singleton]() { deleteOnExit(deleter_t([singleton]() {
#ifndef NDEBUG
destroyed = true; destroyed = true;
#endif
CreateUsingNew<T>::destroy(singleton); CreateUsingNew<T>::destroy(singleton);
})); }));
return singleton; return singleton;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment