Skip to content
Snippets Groups Projects
Commit f19517d7 authored by Tobias Malkmus's avatar Tobias Malkmus
Browse files

[bugfix] add move semantics to DynamicVector

Gcc 4.6 cannot generate default move constructor for classes containing a
DynamicVector because there is no move constructor and the copy constructor
is non-trivial.
This patch fixes this, by adding move semantics.
parent 099ad827
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@
#include <complex>
#include <cstring>
#include <limits>
#include <utility>
#include "exceptions.hh"
#include "genericiterator.hh"
......@@ -81,6 +82,11 @@ namespace Dune {
_data(x._data)
{}
//! Move constructor
DynamicVector(DynamicVector && x) :
_data(std::move(x._data))
{}
template< class T >
DynamicVector(const DynamicVector< T, Allocator > & x) :
_data(x.begin(), x.end(), x.get_allocator())
......@@ -99,6 +105,20 @@ namespace Dune {
using Base::operator=;
//! Copy assignment operator
DynamicVector &operator=(const DynamicVector &other)
{
_data = other._data;
return *this;
}
//! Move assignment operator
DynamicVector &operator=(DynamicVector &&other)
{
_data = std::move(other._data);
return *this;
}
//==== forward some methods of std::vector
/** \brief Number of elements for which memory has been allocated.
......@@ -142,7 +162,7 @@ namespace Dune {
for( typename DynamicVector< K, Allocator >::size_type i = 0; i < w.size(); ++i )
in >> w[ i ];
if(in)
v = w;
v = std::move(w);
return in;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment