From: danshapero Date: Fri, 1 Apr 2016 03:53:55 +0000 (-0700) Subject: Added move constructor to Subscriptor X-Git-Tag: v8.5.0-rc1~1133^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89c30cd37cc42bfac25ec3edc16b1ac1e42c6309;p=dealii.git 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. --- 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 }