From: danshapero Date: Sat, 16 Apr 2016 00:24:11 +0000 (-0700) Subject: Added move constructor to IndexSet X-Git-Tag: v8.5.0-rc1~1094^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8cc165c6ecced627e63b556f4869a47e3f8954f;p=dealii.git Added move constructor to IndexSet --- diff --git a/doc/news/changes.h b/doc/news/changes.h index 12585b6aaf..17fca73239 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -202,6 +202,11 @@ inconvenience this causes.
    +
  1. New: Added move operations to IndexSet. +
    + (Daniel Shapero, 2016/04/19) +
  2. +
  3. 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 diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 99e191702b..780c8d8e1f 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -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 index 0000000000..089aca8911 --- /dev/null +++ b/tests/base/index_set_24.cc @@ -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 + +#include +#include + +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 index 0000000000..f1f45918b2 --- /dev/null +++ b/tests/base/index_set_24.output @@ -0,0 +1,7 @@ + +DEAL::100, 20 +DEAL::100, 20 +DEAL::0, 0 +DEAL::200, 35 +DEAL::200, 35 +DEAL::0, 0