From cf62656b32f3f5b2f954daef045e89aefefd9bc9 Mon Sep 17 00:00:00 2001 From: danshapero Date: Mon, 16 May 2016 15:56:21 -0700 Subject: [PATCH] Added test for aligned vector move ctor/assignment operator --- tests/base/aligned_vector_move.cc | 69 +++++++++++++++++++ .../aligned_vector_move.with_cxx11=on.output | 9 +++ 2 files changed, 78 insertions(+) create mode 100644 tests/base/aligned_vector_move.cc create mode 100644 tests/base/aligned_vector_move.with_cxx11=on.output diff --git a/tests/base/aligned_vector_move.cc b/tests/base/aligned_vector_move.cc new file mode 100644 index 0000000000..b573443dfe --- /dev/null +++ b/tests/base/aligned_vector_move.cc @@ -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 + +#include "../tests.h" +#include +#include + +#include + + +void test() +{ + typedef AlignedVector 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 index 0000000000..30231348bd --- /dev/null +++ b/tests/base/aligned_vector_move.with_cxx11=on.output @@ -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 -- 2.39.5