From 2383e8e3528401071ac03e20f0b8ccaf1c4c17ff Mon Sep 17 00:00:00 2001 From: Lasse Hinrichsen <lh1887@mi.fu-berlin.de> Date: Fri, 7 Dec 2018 14:06:39 +0100 Subject: [PATCH] [VariableBlockVector] Move constructor and assignment --- dune/istl/test/vbvectortest.cc | 5 +++++ dune/istl/vbvector.hh | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/dune/istl/test/vbvectortest.cc b/dune/istl/test/vbvectortest.cc index 2ecd29cf9..89e563f82 100644 --- a/dune/istl/test/vbvectortest.cc +++ b/dune/istl/test/vbvectortest.cc @@ -87,5 +87,10 @@ int main() testVectorSpaceOperations(v5); testScalarProduct(v5); + // check move construction + auto v6 = std::move(v4); + suite.check(v6.size()==20, "Check size of moved-constructed object"); + suite.check(v6[0].size() == 8, "Check if blocksize of move constructed vector survived"); + return suite.exit(); } diff --git a/dune/istl/vbvector.hh b/dune/istl/vbvector.hh index 869bfa12a..6e2b4cb77 100644 --- a/dune/istl/vbvector.hh +++ b/dune/istl/vbvector.hh @@ -146,6 +146,25 @@ namespace Dune { ~VariableBlockVector() = default; + void swap(VariableBlockVector& other) { + std::swap(storage_, other.storage_); + std::swap(block, other.block); + std::swap(initialized, other.initialized); + + other.syncBaseArray(); + syncBaseArray(); + } + + // move constructor: + VariableBlockVector(VariableBlockVector&& tmp) { + swap(tmp); + } + + // move assignment + VariableBlockVector& operator=(VariableBlockVector&& tmp) { + swap(tmp); + return *this; + } //! same effect as constructor with same argument void resize (size_type _nblocks) -- GitLab