84 std::is_move_assignable_v<T>))
99 Lazy(
const Lazy &other);
108 Lazy(Lazy &&other)
noexcept;
119 operator=(
const Lazy &other);
131 operator=(Lazy &&other)
noexcept;
159 template <
typename Callable>
161 ensure_initialized(
const Callable &creator)
const
210 template <
typename Callable>
212 value_or_initialize(
const Callable &creator)
const
221 template <
typename Callable>
223 value_or_initialize(
const Callable &creator)
231 memory_consumption()
const;
237 mutable std::optional<T> object;
244 mutable std::atomic<bool> object_is_initialized;
263 std::is_move_assignable_v<T>))
264inline Lazy<T>::Lazy()
265 : object_is_initialized(false)
271 std::is_move_assignable_v<T>))
272inline Lazy<T>::Lazy(
const Lazy &other)
273 : object(other.object)
275 object_is_initialized.store(other.object_is_initialized.load());
281 std::is_move_assignable_v<T>))
282inline Lazy<T>::Lazy(Lazy &&other) noexcept
283 : object(std::move(other.object))
285 object_is_initialized.store(other.object_is_initialized.load());
292 other.object_is_initialized.store(
false);
293 other.object.reset();
299 std::is_move_assignable_v<T>))
300inline Lazy<T> &Lazy<T>::operator=(
const Lazy &other)
302 object = other.object;
303 object_is_initialized.store(other.object_is_initialized.load());
310 std::is_move_assignable_v<T>))
311inline Lazy<T> &Lazy<T>::operator=(Lazy &&other)
noexcept
313 object = std::move(other.object);
314 object_is_initialized.store(other.object_is_initialized.load());
321 other.object_is_initialized.store(
false);
322 other.object.reset();
330 std::is_move_assignable_v<T>))
331inline void Lazy<T>::reset() noexcept
333 object_is_initialized.store(
false);
340 std::is_move_assignable_v<T>))
341template <
typename Callable>
343 void Lazy<T>::ensure_initialized(
const Callable &creator)
const
364 if (!object_is_initialized.load(std::memory_order_acquire))
365#ifdef DEAL_II_HAVE_CXX20
369 std::lock_guard<std::mutex> lock(initialization_mutex);
379 if (!object_is_initialized.load(std::memory_order_relaxed))
382 object.emplace(std::move(creator()));
391 object_is_initialized.store(
true, std::memory_order_release);
398 "The internal std::optional<T> object does not contain a valid object "
399 "even though we have just initialized it."));
405 std::is_move_assignable_v<T>))
414 return (object_is_initialized &&
object.has_value());
420 std::is_move_assignable_v<T>))
424 object_is_initialized &&
object.has_value(),
426 "value() has been called but the contained object has not been "
427 "initialized. Did you forget to call 'ensure_initialized()' first?"));
429 return object.value();
435 std::is_move_assignable_v<T>))
439 object_is_initialized &&
object.has_value(),
441 "value() has been called but the contained object has not been "
442 "initialized. Did you forget to call 'ensure_initialized()' first?"));
444 return object.value();
450 std::is_move_assignable_v<T>))
451template <
typename Callable>
453 const Callable &creator)
const
456 ensure_initialized(creator);
457 return object.value();
463 std::is_move_assignable_v<T>))
464template <
typename Callable>
466 const Callable &creator)
469 ensure_initialized(creator);
470 return object.value();
476 std::is_move_assignable_v<T>))
477std::size_t Lazy<T>::memory_consumption()
const
480 sizeof(*this) -
sizeof(object);
#define DEAL_II_ALWAYS_INLINE
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)