]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added move constructor to IndexSet 2513/head
authordanshapero <shapero.daniel@gmail.com>
Sat, 16 Apr 2016 00:24:11 +0000 (17:24 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Tue, 19 Apr 2016 17:30:36 +0000 (10:30 -0700)
doc/news/changes.h
include/deal.II/base/index_set.h
tests/base/index_set_24.cc [new file with mode: 0644]
tests/base/index_set_24.output [new file with mode: 0644]

index 12585b6aafcfdc6897a12172951b795dd33de0ce..17fca7323937dada64a7fc33210c110c4eaa3b96 100644 (file)
@@ -202,6 +202,11 @@ inconvenience this causes.
 
 <ol>
 
+ <li> New: Added move operations to IndexSet.
+ <br>
+ (Daniel Shapero, 2016/04/19)
+ </li>
+
  <li> Improved: The parallel loops in the deal.II Vector class for
  vector-vector operations have been revised for performance. This includes
  adjusting the minimum parallel grain size to 4096 vector entries and using an
index 99e191702b54f0b04402b6ac50bb6b9635f0f4a6..780c8d8e1f3fa42d39f2069145897a1c877fc019 100644 (file)
@@ -105,6 +105,29 @@ public:
    */
   explicit IndexSet (const size_type size);
 
+#ifdef DEAL_II_WITH_CXX11
+  /**
+   * Copy constructor.
+   */
+  IndexSet (const IndexSet &) = default;
+
+  /**
+   * Copy assignment operator.
+   */
+  IndexSet &operator= (const IndexSet &) = default;
+
+  /**
+   * Move constructor. Create a new IndexSet by transferring the internal data
+   * of the input set.
+   */
+  IndexSet (IndexSet &&is);
+
+  /**
+   * Move assignment operator. Transfer the internal data of the input set into
+   * the current one.
+   */
+  IndexSet &operator= (IndexSet &&is);
+#endif
 
 #ifdef DEAL_II_WITH_TRILINOS
   /**
@@ -1218,6 +1241,46 @@ IndexSet::IndexSet (const size_type size)
 
 
 
+#ifdef DEAL_II_WITH_CXX11
+
+inline
+IndexSet::IndexSet (IndexSet &&is)
+  :
+  ranges (std::move(is.ranges)),
+  is_compressed (is.is_compressed),
+  index_space_size (is.index_space_size),
+  largest_range (is.largest_range)
+{
+  is.ranges.clear ();
+  is.is_compressed = true;
+  is.index_space_size = 0;
+  is.largest_range = numbers::invalid_unsigned_int;
+
+  compress ();
+}
+
+
+inline
+IndexSet &IndexSet::operator= (IndexSet &&is)
+{
+  ranges = std::move (is.ranges);
+  is_compressed = is.is_compressed;
+  index_space_size = is.index_space_size;
+  largest_range = is.largest_range;
+
+  is.ranges.clear ();
+  is.is_compressed = true;
+  is.index_space_size = 0;
+  is.largest_range = numbers::invalid_unsigned_int;
+
+  compress ();
+
+  return *this;
+}
+
+#endif
+
+
 inline
 void
 IndexSet::clear ()
diff --git a/tests/base/index_set_24.cc b/tests/base/index_set_24.cc
new file mode 100644 (file)
index 0000000..089aca8
--- /dev/null
@@ -0,0 +1,55 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Check that the move constructor for `IndexSet` works properly
+
+#include "../tests.h"
+#include <fstream>
+
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/index_set.h>
+
+int main()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+
+  IndexSet is1(100);
+  is1.add_range(0, 10);
+  is1.add_range(30, 40);
+
+  deallog << is1.size() << ", " << is1.n_elements() << std::endl;
+
+  // Test that move construction works correctly and that the moved object is
+  // restored to the default state
+  IndexSet is2 = std::move(is1);
+
+  deallog << is2.size() << ", " << is2.n_elements() << std::endl;
+  deallog << is1.size() << ", " << is1.n_elements() << std::endl;
+
+  // Test that re-initializing the moved variable works
+  is1.set_size(200);
+  is1.add_range(90, 110);
+  is1.add_range(130, 140);
+  is1.add_range(145, 150);
+
+  deallog << is1.size() << ", " << is1.n_elements() << std::endl;
+
+  // Test that move assignment works correctly and that the moved object is
+  // restored to the default state
+  is2 = std::move(is1);
+  deallog << is2.size() << ", " << is2.n_elements() << std::endl;
+  deallog << is1.size() << ", " << is1.n_elements() << std::endl;
+}
diff --git a/tests/base/index_set_24.output b/tests/base/index_set_24.output
new file mode 100644 (file)
index 0000000..f1f4591
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::100, 20
+DEAL::100, 20
+DEAL::0, 0
+DEAL::200, 35
+DEAL::200, 35
+DEAL::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.