31 #include <MUtils/Exception.h> 34 #include <QAtomicPointer> 48 template<
typename T>
class Lazy 51 Lazy(std::function<T*(
void)> &&initializer) : m_initializer(initializer) { }
56 while (!(value = m_value.fetchAndAddOrdered(0)))
58 if (!(value = m_initializer()))
60 MUTILS_THROW(
"Initializer returned NULL pointer!");
62 if (m_value.testAndSetOrdered(NULL, value))
74 if(T *
const value = m_value.fetchAndStoreOrdered(NULL))
81 QAtomicPointer<T> m_value;
82 const std::function<T*(void)> m_initializer;
This file contains miscellaneous functions that are generally useful for Qt-based applications...
Lazy initialization template class.
Definition: Lazy.h:48
Global MUtils namespace.
Definition: CPUFeatures.h:37