From: danshapero Date: Tue, 12 Apr 2016 16:51:45 +0000 (-0700) Subject: Added move ctor to BlockIndices X-Git-Tag: v8.5.0-rc1~1106^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85778bbfa35d15058ecee14b5b67bd42a431b998;p=dealii.git Added move ctor to BlockIndices --- diff --git a/include/deal.II/lac/block_indices.h b/include/deal.II/lac/block_indices.h index bc4126f40a..c10f1cb611 100644 --- a/include/deal.II/lac/block_indices.h +++ b/include/deal.II/lac/block_indices.h @@ -74,6 +74,22 @@ public: */ BlockIndices (const std::vector &block_sizes); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move constructor. Initialize a new object by stealing the internal data of + * another BlockIndices object. + * + * @note This constructor is only available if deal.II is configured with + * C++11 support. + */ + BlockIndices (BlockIndices &&b); + + /** + * Copy constructor. + */ + BlockIndices (const BlockIndices &) = default; +#endif + /** * Specialized constructor for a structure with blocks of equal size. */ @@ -165,6 +181,14 @@ public: */ BlockIndices &operator = (const BlockIndices &b); +#ifdef DEAL_II_WITH_CXX11 + /** + * Move assignment operator. Move another BlockIndices object onto the + * current one by transferring its contents. + */ + BlockIndices &operator = (BlockIndices &&); +#endif + /** * Compare whether two objects are the same, i.e. whether the number of * blocks and the sizes of all blocks are equal. @@ -285,6 +309,23 @@ BlockIndices::BlockIndices (const std::vector &block_sizes) } + +#ifdef DEAL_II_WITH_CXX11 + +inline +BlockIndices::BlockIndices (BlockIndices &&b) + : + n_blocks(b.n_blocks), + start_indices(std::move(b.start_indices)) +{ + b.n_blocks = 0; + b.start_indices = std::vector(1, 0); +} + +#endif + + + inline void BlockIndices::push_back(const size_type sz) @@ -391,6 +432,23 @@ BlockIndices::operator = (const BlockIndices &b) +#ifdef DEAL_II_WITH_CXX11 +inline +BlockIndices & +BlockIndices::operator = (BlockIndices &&b) +{ + start_indices = std::move(b.start_indices); + n_blocks = b.n_blocks; + + b.start_indices = std::vector(1, 0); + b.n_blocks = 0; + + return *this; +} +#endif + + + inline bool BlockIndices::operator == (const BlockIndices &b) const diff --git a/tests/lac/block_indices.cc b/tests/lac/block_indices.cc index 7ecdd03d3a..8991600752 100644 --- a/tests/lac/block_indices.cc +++ b/tests/lac/block_indices.cc @@ -84,4 +84,8 @@ int main() BlockIndices bi2(v); test(bi2); + + BlockIndices bi3 = std::move(bi2); + test(bi3); + deallog << "empty: " << bi2 << std::endl; } diff --git a/tests/lac/block_indices.output b/tests/lac/block_indices.output index 6c898fc60c..8e55eb7eb2 100644 --- a/tests/lac/block_indices.output +++ b/tests/lac/block_indices.output @@ -25,3 +25,9 @@ DEAL::start: 0 4 7 9 DEAL::string: [4->4,3,2,1|10] DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 +DEAL::sizes: 4:[4 3 2 1]->10 +DEAL::start: 0 4 7 9 +DEAL::string: [4->4,3,2,1|10] +DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 +DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 +DEAL::empty: 0:[]->0