From 3d692b01c4273b54c77896faeb6ddb72075e4748 Mon Sep 17 00:00:00 2001 From: danshapero Date: Tue, 12 Apr 2016 22:29:55 -0700 Subject: [PATCH] Added default move ctor/assignment to BlockVector, BlockVectorBase This makes a moved BlockVector have the right post-condition, i.e. the state it would have after default construction. --- include/deal.II/lac/block_vector.h | 18 ++----------- include/deal.II/lac/block_vector.templates.h | 11 -------- include/deal.II/lac/block_vector_base.h | 26 +++++++++++++++++++ ...ector_move_operations.with_cxx11=on.output | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/include/deal.II/lac/block_vector.h b/include/deal.II/lac/block_vector.h index 9f5aabdd17..ac8a467d42 100644 --- a/include/deal.II/lac/block_vector.h +++ b/include/deal.II/lac/block_vector.h @@ -112,7 +112,7 @@ public: * @note This constructor is only available if deal.II is configured with * C++11 support. */ - BlockVector (BlockVector &&v); + BlockVector (BlockVector &&v) = default; #endif @@ -208,7 +208,7 @@ public: * @note This operator is only available if deal.II is configured with C++11 * support. */ - BlockVector &operator= (BlockVector &&v); + BlockVector &operator= (BlockVector &&v) = default; #endif /** @@ -422,20 +422,6 @@ BlockVector::operator= (const BlockVector &v) -#ifdef DEAL_II_WITH_CXX11 -template -inline -BlockVector & -BlockVector::operator= (BlockVector &&v) -{ - swap(v); - - return *this; -} -#endif - - - template inline BlockVector & diff --git a/include/deal.II/lac/block_vector.templates.h b/include/deal.II/lac/block_vector.templates.h index 0f1fcbe6f0..eb77a776a9 100644 --- a/include/deal.II/lac/block_vector.templates.h +++ b/include/deal.II/lac/block_vector.templates.h @@ -61,17 +61,6 @@ BlockVector::BlockVector (const BlockVector &v) } -#ifdef DEAL_II_WITH_CXX11 -template -BlockVector::BlockVector (BlockVector &&v) - : - BlockVectorBase > () -{ - swap(v); -} -#endif - - #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG template diff --git a/include/deal.II/lac/block_vector_base.h b/include/deal.II/lac/block_vector_base.h index 17d5eebaeb..fd7ddb6f74 100644 --- a/include/deal.II/lac/block_vector_base.h +++ b/include/deal.II/lac/block_vector_base.h @@ -577,6 +577,23 @@ public: */ BlockVectorBase (); +#ifdef DEAL_II_WITH_CXX11 + /** + * Copy constructor. + */ + BlockVectorBase (const BlockVectorBase &V) = default; + + /** + * Move constructor. Each block of the vector @p V is moved into the current + * object if the underlying VectorType is move-constructible, + * otherwise they are copied. + * + * @note This constructor is only available if deal.II is configured with + * C++11 support. + */ + BlockVectorBase (BlockVectorBase &&V) = default; +#endif + /** * Update internal structures after resizing vectors. Whenever you reinited * a block of a block vector, the internal data structures are corrupted. @@ -723,6 +740,14 @@ public: BlockVectorBase & operator= (const BlockVectorBase &V); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move assignment operator. Move each block of the vector @p V into the + * current object if `VectorType` is move-constructible, otherwise copy them. + */ + BlockVectorBase &operator= (BlockVectorBase &&V) = default; +#endif + /** * Copy operator for template arguments of different types. */ @@ -1468,6 +1493,7 @@ namespace internal } //namespace internal + template inline BlockVectorBase::BlockVectorBase () diff --git a/tests/lac/block_vector_move_operations.with_cxx11=on.output b/tests/lac/block_vector_move_operations.with_cxx11=on.output index bf0d55296d..a86c63cf10 100644 --- a/tests/lac/block_vector_move_operations.with_cxx11=on.output +++ b/tests/lac/block_vector_move_operations.with_cxx11=on.output @@ -30,7 +30,7 @@ DEAL::[block 1 ] 10.0000 11.0000 DEAL::[block 2 ] 20.0000 21.0000 DEAL::[block 3 ] 30.0000 31.0000 DEAL::[block 4 ] 40.0000 41.0000 -DEAL::old object size: 5 +DEAL::old object size: 0 DEAL::Block vector: move assignemnt: DEAL::[block 0 ] 0.00000 1.00000 DEAL::[block 1 ] 10.0000 11.0000 -- 2.39.5