]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #16295 from bangerth/lazy
authorDaniel Arndt <arndtd@ornl.gov>
Tue, 28 Nov 2023 22:58:45 +0000 (17:58 -0500)
committerGitHub <noreply@github.com>
Tue, 28 Nov 2023 22:58:45 +0000 (17:58 -0500)
1  2 
include/deal.II/base/lazy.h

index dbc01eeed9ddc0a8cf78dc5d5e625828bc83f6b3,b3774f3bbedb400b38207b2cf679d25142b80292..84975826a16d4388943ea271af10e13a7168a860
@@@ -264,12 -269,18 +278,20 @@@ inline Lazy<T>::Lazy(const Lazy &other
  
  
  template <typename T>
 +DEAL_II_CXX20_REQUIRES((std::is_move_constructible_v<T> &&
 +                        std::is_move_assignable_v<T>))
  inline Lazy<T>::Lazy(Lazy &&other) noexcept
-   : object(other.object)
+   : object(std::move(other.object))
  {
    object_is_initialized.store(other.object_is_initialized.load());
+   // Mark the other object as uninitialized. This is marginally non-trivial
+   // because moving from std::optional<T> does *not* result in an empty
+   // std::optional<T> but instead one that does contain a T, but one that
+   // has been moved from -- typically something akin to a default-initialized
+   // T. That seems undesirable, so reset everything to an empty state.
+   other.object_is_initialized.store(false);
+   other.object.reset();
  }
  
  
@@@ -285,12 -295,20 +307,21 @@@ inline Lazy<T> &Lazy<T>::operator=(cons
  
  
  template <typename T>
 -inline Lazy<T> &
 -Lazy<T>::operator=(Lazy &&other) noexcept
 +DEAL_II_CXX20_REQUIRES((std::is_move_constructible_v<T> &&
 +                        std::is_move_assignable_v<T>))
 +inline Lazy<T> &Lazy<T>::operator=(Lazy &&other) noexcept
  {
-   object = other.object;
+   object = std::move(other.object);
    object_is_initialized.store(other.object_is_initialized.load());
+   // Mark the other object as uninitialized. This is marginally non-trivial
+   // because moving from std::optional<T> does *not* result in an empty
+   // std::optional<T> but instead one that does contain a T, but one that
+   // has been moved from -- typically something akin to a default-initialized
+   // T. That seems undesirable, so reset everything to an empty state.
+   other.object_is_initialized.store(false);
+   other.object.reset();
    return *this;
  }
  

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.