From 89c30cd37cc42bfac25ec3edc16b1ac1e42c6309 Mon Sep 17 00:00:00 2001 From: danshapero Date: Thu, 31 Mar 2016 20:53:55 -0700 Subject: [PATCH] Added move constructor to Subscriptor A subscriptor can only be moved if there are no other objects subscribing to it. This condition is already checked in a sensible way in the destructor for Subscriptor, so rather than add a bunch of boilerplate, the move constructor just invokes the destructor. --- include/deal.II/base/subscriptor.h | 10 ++++++++++ source/base/subscriptor.cc | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/deal.II/base/subscriptor.h b/include/deal.II/base/subscriptor.h index 17023d8ef3..6f968c7bf7 100644 --- a/include/deal.II/base/subscriptor.h +++ b/include/deal.II/base/subscriptor.h @@ -69,6 +69,16 @@ public: */ Subscriptor(const Subscriptor &); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. + * + * An object inheriting from Subscriptor can only be moved if no other + * objects are subscribing to it. + */ + Subscriptor(Subscriptor&&); +#endif + /** * Destructor, asserting that the counter is zero. */ diff --git a/source/base/subscriptor.cc b/source/base/subscriptor.cc index c3a61421ba..07240b88e9 100644 --- a/source/base/subscriptor.cc +++ b/source/base/subscriptor.cc @@ -62,6 +62,22 @@ Subscriptor::Subscriptor (const Subscriptor &) {} + +#ifdef DEAL_II_WITH_CXX11 +Subscriptor::Subscriptor (Subscriptor &&subscriptor) + : + counter(0), + object_info (subscriptor.object_info) +{ + // Explicitly invoke the destructor of `Subscriptor` for the object + // to be moved from in order to guarantee that we're not moving an + // object that has subscriptions. + subscriptor.~Subscriptor(); +} +#endif + + + Subscriptor::~Subscriptor () { // check whether there are still @@ -136,6 +152,13 @@ Subscriptor::~Subscriptor () // do_unsubscribe below that the // object is unused now. counter = 0; + +#ifdef DEAL_II_WITH_CXX11 + object_info = nullptr; +#else + object_info = 0; +#endif + #endif } -- 2.39.5