]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added move ctor to BlockIndices
authordanshapero <shapero.daniel@gmail.com>
Tue, 12 Apr 2016 16:51:45 +0000 (09:51 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Wed, 13 Apr 2016 19:03:18 +0000 (12:03 -0700)
include/deal.II/lac/block_indices.h
tests/lac/block_indices.cc
tests/lac/block_indices.output

index bc4126f40af805b018d77a70a4235b701417ac3e..c10f1cb611b906224b1ae0da9b6b45f7a6eb78ba 100644 (file)
@@ -74,6 +74,22 @@ public:
    */
   BlockIndices (const std::vector<size_type> &block_sizes);
 
+#ifdef DEAL_II_WITH_CXX11
+  /**
+   * Move constructor. Initialize a new object by stealing the internal data of
+   * another BlockIndices object.
+   *
+   * @note This constructor is only available if deal.II is configured with
+   * C++11 support.
+   */
+  BlockIndices (BlockIndices &&b);
+
+  /**
+   * Copy constructor.
+   */
+  BlockIndices (const BlockIndices &) = default;
+#endif
+
   /**
    * Specialized constructor for a structure with blocks of equal size.
    */
@@ -165,6 +181,14 @@ public:
    */
   BlockIndices &operator = (const BlockIndices &b);
 
+#ifdef DEAL_II_WITH_CXX11
+  /**
+   * Move assignment operator. Move another BlockIndices object onto the
+   * current one by transferring its contents.
+   */
+  BlockIndices &operator = (BlockIndices &&);
+#endif
+
   /**
    * Compare whether two objects are the same, i.e. whether the number of
    * blocks and the sizes of all blocks are equal.
@@ -285,6 +309,23 @@ BlockIndices::BlockIndices (const std::vector<size_type> &block_sizes)
 }
 
 
+
+#ifdef DEAL_II_WITH_CXX11
+
+inline
+BlockIndices::BlockIndices (BlockIndices &&b)
+  :
+  n_blocks(b.n_blocks),
+  start_indices(std::move(b.start_indices))
+{
+  b.n_blocks = 0;
+  b.start_indices = std::vector<size_type>(1, 0);
+}
+
+#endif
+
+
+
 inline
 void
 BlockIndices::push_back(const size_type sz)
@@ -391,6 +432,23 @@ BlockIndices::operator = (const BlockIndices &b)
 
 
 
+#ifdef DEAL_II_WITH_CXX11
+inline
+BlockIndices &
+BlockIndices::operator = (BlockIndices &&b)
+{
+  start_indices = std::move(b.start_indices);
+  n_blocks = b.n_blocks;
+
+  b.start_indices = std::vector<size_type>(1, 0);
+  b.n_blocks = 0;
+
+  return *this;
+}
+#endif
+
+
+
 inline
 bool
 BlockIndices::operator == (const BlockIndices &b) const
index 7ecdd03d3a1f6903d469478a79cde312c0514807..89916007520b7bdb8b05258eb4813a80cd206410 100644 (file)
@@ -84,4 +84,8 @@ int main()
 
   BlockIndices bi2(v);
   test(bi2);
+
+  BlockIndices bi3 = std::move(bi2);
+  test(bi3);
+  deallog << "empty: " << bi2 << std::endl;
 }
index 6c898fc60c097f2c38132619b6e80d61f2eadbfc..8e55eb7eb2960eb950b0d405e89fccdce008d38b 100644 (file)
@@ -25,3 +25,9 @@ DEAL::start:    0 4 7 9
 DEAL::string: [4->4,3,2,1|10]
 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0
 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0
+DEAL::sizes: 4:[4 3 2 1]->10
+DEAL::start:    0 4 7 9
+DEAL::string: [4->4,3,2,1|10]
+DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0
+DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0
+DEAL::empty: 0:[]->0

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.