From: Daniel Arndt Date: Tue, 28 Nov 2023 22:58:45 +0000 (-0500) Subject: Merge pull request #16295 from bangerth/lazy X-Git-Tag: relicensing~276 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f973201c2fa5116f2a931f2598c85e859e6389b;p=dealii.git Merge pull request #16295 from bangerth/lazy --- 3f973201c2fa5116f2a931f2598c85e859e6389b diff --cc include/deal.II/base/lazy.h index dbc01eeed9,b3774f3bbe..84975826a1 --- a/include/deal.II/base/lazy.h +++ b/include/deal.II/base/lazy.h @@@ -264,12 -269,18 +278,20 @@@ inline Lazy::Lazy(const Lazy &other template +DEAL_II_CXX20_REQUIRES((std::is_move_constructible_v && + std::is_move_assignable_v)) inline Lazy::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 does *not* result in an empty + // std::optional 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 &Lazy::operator=(cons template -inline Lazy & -Lazy::operator=(Lazy &&other) noexcept +DEAL_II_CXX20_REQUIRES((std::is_move_constructible_v && + std::is_move_assignable_v)) +inline Lazy &Lazy::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 does *not* result in an empty + // std::optional 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; }