From: Matthias Maier Date: Fri, 1 May 2015 20:19:21 +0000 (+0200) Subject: Add move constructor and operator to TrilinosWrappers::MPI::Vector and TrilinosWrappe... X-Git-Tag: v8.3.0-rc1~203^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00aea7cd9f146f3c6c097d6956f8600bea2dd4ea;p=dealii.git Add move constructor and operator to TrilinosWrappers::MPI::Vector and TrilinosWrappers::MPI::BlockVector --- diff --git a/include/deal.II/lac/trilinos_parallel_block_vector.h b/include/deal.II/lac/trilinos_parallel_block_vector.h index a604916467..3deb3b709d 100644 --- a/include/deal.II/lac/trilinos_parallel_block_vector.h +++ b/include/deal.II/lac/trilinos_parallel_block_vector.h @@ -128,7 +128,22 @@ namespace TrilinosWrappers * Copy-Constructor. Set all the properties of the parallel vector to * those of the given argument and copy the elements. */ - BlockVector (const BlockVector &V); + BlockVector (const BlockVector &v); + +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. Creates a new vector by stealing the internal data + * of the vector @p v. + * + * @note This constructor is only available if deal.II is configured with + * C++11 support. + */ + BlockVector (BlockVector &&v) + { + swap(v); + v.reinit (0); + } +#endif /** * Creates a block vector consisting of num_blocks components, @@ -146,20 +161,37 @@ namespace TrilinosWrappers * Copy operator: fill all components of the vector that are locally * stored with the given scalar value. */ - BlockVector & - operator = (const value_type s); + BlockVector &operator= (const value_type s); /** * Copy operator for arguments of the same type. */ - BlockVector & - operator = (const BlockVector &V); + BlockVector &operator= (const BlockVector &v); + +#ifdef DEAL_II_WITH_CXX11 + /** + * Move the given vector. This operator replaces the present vector with + * @p v by efficiently swapping the internal data structures. @p v is + * left empty. + * + * @note This operator is only available if deal.II is configured with + * C++11 support. + */ + BlockVector &operator= (BlockVector &&v) + { + swap(v); + // be nice and reset v to zero + v.reinit (0); + + return *this; + } +#endif /** * Copy operator for arguments of the localized Trilinos vector type. */ BlockVector & - operator = (const ::dealii::TrilinosWrappers::BlockVector &V); + operator= (const ::dealii::TrilinosWrappers::BlockVector &v); /** * Another copy function. This one takes a deal.II block vector and @@ -172,8 +204,7 @@ namespace TrilinosWrappers * accept only one possible number type in the deal.II vector. */ template - BlockVector & - operator = (const ::dealii::BlockVector &V); + BlockVector &operator= (const ::dealii::BlockVector &v); /** * Reinitialize the BlockVector to contain as many blocks as there are @@ -400,7 +431,7 @@ namespace TrilinosWrappers template BlockVector & - BlockVector::operator = (const ::dealii::BlockVector &v) + BlockVector::operator= (const ::dealii::BlockVector &v) { if (n_blocks() != v.n_blocks()) { diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index b91cc94844..c561202d75 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -284,7 +284,23 @@ namespace TrilinosWrappers /** * Copy constructor using the given vector. */ - Vector (const Vector &V); + Vector (const Vector &v); + +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. Creates a new vector by stealing the internal data + * of the vector @p v. + * + * @note This constructor is only available if deal.II is configured with + * C++11 support. + */ + Vector (Vector &&v) + { + swap(v); + // be nice and reset v to zero + v.clear(); + } +#endif /** * Destructor. @@ -326,15 +342,33 @@ namespace TrilinosWrappers * function to make the example given in the discussion about making the * constructor explicit work. */ - Vector &operator = (const TrilinosScalar s); + Vector &operator= (const TrilinosScalar s); /** * Copy the given vector. Resize the present vector if necessary. In * this case, also the Epetra_Map that designs the parallel partitioning * is taken from the input vector. */ - Vector & - operator = (const Vector &V); + Vector &operator= (const Vector &v); + +#ifdef DEAL_II_WITH_CXX11 + /** + * Move the given vector. This operator replaces the present vector with + * @p v by efficiently swapping the internal data structures. @p v is + * left empty. + * + * @note This operator is only available if deal.II is configured with + * C++11 support. + */ + Vector &operator= (Vector &&v) + { + swap(v); + // be nice and reset v to zero + v.clear(); + + return *this; + } +#endif /** * Copy operator from a given localized vector (present on all @@ -343,8 +377,7 @@ namespace TrilinosWrappers * object) already is of the same size as the right hand side vector. * Otherwise, an exception will be thrown. */ - Vector & - operator = (const ::dealii::TrilinosWrappers::Vector &V); + Vector &operator= (const ::dealii::TrilinosWrappers::Vector &v); /** * Another copy function. This one takes a deal.II vector and copies it @@ -355,8 +388,7 @@ namespace TrilinosWrappers * the reinit(const Epetra_Map &input_map) function. */ template - Vector & - operator = (const ::dealii::Vector &v); + Vector &operator= (const ::dealii::Vector &v); /** * This reinit function is meant to be used for parallel calculations @@ -649,9 +681,9 @@ namespace TrilinosWrappers inline Vector & - Vector::operator = (const TrilinosScalar s) + Vector::operator= (const TrilinosScalar s) { - VectorBase::operator = (s); + VectorBase::operator= (s); return *this; } @@ -659,7 +691,7 @@ namespace TrilinosWrappers template Vector & - Vector::operator = (const ::dealii::Vector &v) + Vector::operator= (const ::dealii::Vector &v) { if (size() != v.size()) { @@ -678,7 +710,7 @@ namespace TrilinosWrappers } -#endif +#endif /* DOXYGEN */ } /* end of namespace MPI */ @@ -817,28 +849,25 @@ namespace TrilinosWrappers * to make the example given in the discussion about making the * constructor explicit work. */ - Vector &operator = (const TrilinosScalar s); + Vector &operator= (const TrilinosScalar s); /** * Sets the left hand argument to the (parallel) Trilinos Vector. * Equivalent to the @p reinit function. */ - Vector & - operator = (const MPI::Vector &V); + Vector &operator= (const MPI::Vector &v); /** * Sets the left hand argument to the deal.II vector. */ template - Vector & - operator = (const ::dealii::Vector &V); + Vector &operator= (const ::dealii::Vector &v); /** * Copy operator. Copies both the dimension and the content in the right * hand argument. */ - Vector & - operator = (const Vector &V); + Vector &operator= (const Vector &v); /** * This function does nothing but is there for compatibility with the @p @@ -888,9 +917,9 @@ namespace TrilinosWrappers inline Vector & - Vector::operator = (const TrilinosScalar s) + Vector::operator= (const TrilinosScalar s) { - VectorBase::operator = (s); + VectorBase::operator= (s); return *this; } @@ -899,7 +928,7 @@ namespace TrilinosWrappers template Vector & - Vector::operator = (const ::dealii::Vector &v) + Vector::operator= (const ::dealii::Vector &v) { if (size() != v.size()) {