ensure_initialized(const Callable &creator) const;
+ /**
+ * Returns true if the contained object has been initialized, otherwise
+ * false.
+ */
+ bool
+ has_value() const;
+
+
/**
* Return a const reference to the contained object.
*
}
+template <typename T>
+inline DEAL_II_ALWAYS_INLINE bool
+Lazy<T>::has_value() const
+{
+ //
+ // In principle it would be sufficient to solely check the atomic<bool>
+ // object_is_initialized because the load() is performed with "acquire"
+ // semantics. But just in case let's check the object.has_value() boolean
+ // as well:
+ //
+ return object_is_initialized && object.has_value();
+}
+
+
template <typename T>
inline DEAL_II_ALWAYS_INLINE const T &
Lazy<T>::value() const
{
Assert(
- object.has_value(),
+ object_is_initialized && object.has_value(),
dealii::ExcMessage(
"value() has been called but the contained object has not been "
"initialized. Did you forget to call 'ensure_initialized()' first?"));
Lazy<T>::value()
{
Assert(
- object.has_value(),
+ object_is_initialized && object.has_value(),
dealii::ExcMessage(
"value() has been called but the contained object has not been "
"initialized. Did you forget to call 'ensure_initialized()' first?"));
{
Lazy<int> lazy_integer;
+ deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
+ << std::endl;
lazy_integer.ensure_initialized([&]() {
deallog << "[initializing object]" << std::endl;
return 42;
});
+ deallog << "lazy_integer.has_value() = " << lazy_integer.has_value()
+ << std::endl;
deallog << "lazy_integer.value() = " << lazy_integer.value() << std::endl;
lazy_integer.ensure_initialized([&]() {
+DEAL::lazy_integer.has_value() = 0
DEAL::[initializing object]
+DEAL::lazy_integer.has_value() = 1
DEAL::lazy_integer.value() = 42
DEAL::lazy_integer.value() = 42
DEAL::lazy_integer.value() = ... [initializing object] ... 42