]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added test for aligned vector move ctor/assignment operator
authordanshapero <shapero.daniel@gmail.com>
Mon, 16 May 2016 22:56:21 +0000 (15:56 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Wed, 18 May 2016 00:44:45 +0000 (17:44 -0700)
tests/base/aligned_vector_move.cc [new file with mode: 0644]
tests/base/aligned_vector_move.with_cxx11=on.output [new file with mode: 0644]

diff --git a/tests/base/aligned_vector_move.cc b/tests/base/aligned_vector_move.cc
new file mode 100644 (file)
index 0000000..b573443
--- /dev/null
@@ -0,0 +1,69 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2012 - 2016 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.
+//
+// ---------------------------------------------------------------------
+
+
+// test for C++11 move operations on AlignedVector<unsigned int>
+
+#include "../tests.h"
+#include <iomanip>
+#include <fstream>
+
+#include <deal.II/base/aligned_vector.h>
+
+
+void test()
+{
+  typedef AlignedVector<unsigned int> VEC;
+
+  VEC a(4, 2);
+
+  deallog << "Size: " << a.size() << std::endl;
+
+  VEC b = std::move(a);
+
+  deallog << "Size of new VEC: " << b.size() << std::endl;
+  deallog << "Size of moved VEC: " << a.size() << std::endl;
+
+  deallog << "Contents of new VEC: ";
+  for (unsigned int i = 0; i < b.size(); ++i)
+    deallog << b[i] << " ";
+  deallog << std::endl;
+
+  a.resize(6, 42);
+
+  deallog << "Size of moved VEC after resize: " << a.size() << std::endl;
+
+  deallog << "Contents of new VEC: ";
+  for (unsigned int i = 0; i < a.size(); ++i)
+    deallog << a[i] << " ";
+  deallog << std::endl;
+
+  a = std::move(b);
+
+  deallog << "Size of move-assigned VEC: " << a.size() << std::endl;
+  deallog << "Size of moved VEC: " << b.size() << std::endl;
+}
+
+
+int main()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+
+  return 0;
+}
diff --git a/tests/base/aligned_vector_move.with_cxx11=on.output b/tests/base/aligned_vector_move.with_cxx11=on.output
new file mode 100644 (file)
index 0000000..3023134
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::Size: 4
+DEAL::Size of new VEC: 4
+DEAL::Size of moved VEC: 0
+DEAL::Contents of new VEC: 2 2 2 2 
+DEAL::Size of moved VEC after resize: 6
+DEAL::Contents of new VEC: 42 42 42 42 42 42 
+DEAL::Size of move-assigned VEC: 4
+DEAL::Size of moved VEC: 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.