]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added move constructor to Subscriptor
authordanshapero <shapero.daniel@gmail.com>
Fri, 1 Apr 2016 03:53:55 +0000 (20:53 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Fri, 1 Apr 2016 03:53:55 +0000 (20:53 -0700)
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
source/base/subscriptor.cc

index 17023d8ef3ccf74c901dac4174f83edb6811eb4b..6f968c7bf710fc22fd61bb7fc518a29db81984eb 100644 (file)
@@ -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.
    */
index c3a61421ba7af70a190e5432ca843ae97189b514..07240b88e912b25b77ccf1b2a5e6cc56dbdeff70 100644 (file)
@@ -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
 }
 

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.