diff --git a/dune/istl/test/vbvectortest.cc b/dune/istl/test/vbvectortest.cc index 2ecd29cf9b38269e08dbb1f0196404c4f017b7bc..89e563f82617f4de5b010c204b3119d3a5e09665 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 869bfa12a9e70f4264bf381efa3a9ce1c1016af0..6e2b4cb7728fcb8385153f8ab6281dd61ca519ca 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)