]> https://gitweb.dealii.org/ - dealii.git/commit
base: Implement a Lazy<T> wrapper
authorMatthias Maier <tamiko@43-1.org>
Tue, 24 Oct 2023 16:33:04 +0000 (11:33 -0500)
committerMatthias Maier <tamiko@43-1.org>
Fri, 27 Oct 2023 07:01:36 +0000 (02:01 -0500)
commit3330c02adad931e8c6a7d522f59126ab4b9fa776
tree3f8be7eef8f1729d52ffe4c35c9fd152c82527e5
parentc07ea47b4a950ce5ab94da48c57b0466b6418003
base: Implement a Lazy<T> wrapper

Implement an optimized, thin wrapper that provides a convenient
mechanism for lazy initialization of the contained object on first use.
The class ensures that on-demand initialization of some expensive data
structure happens (a) in a thread-safe manner, and that (b) subsequent
checks in hot paths are cheap:

 - The class implements proper copy and move semantics inherited from
   std::optional. This is particularly desirable for our typical use
   case in deal.II where we want to initialize some payload exactly once
   (and simply copy or move it along with the container).

 - The "passive" call, i.e., when the object is already initialized is
   much cheaper than a call to std::call_once, or thread synchronization
   with a std::shared_mutex (because the initialize() or
   value_or_initialize() functions are inlined and consist of a mere
   check of a boolean followed by a conditional jump).
include/deal.II/base/lazy.h [new file with mode: 0644]

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.