Skip to content

Commit

Permalink
avoid code duplication (move operations)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Aug 25, 2016
1 parent 4f1d71c commit f93b389
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/gsl_vector.cpp
Expand Up @@ -21,6 +21,7 @@

#include <cmath>
#include <string>
#include <utility>

namespace flexiblesusy {

Expand Down Expand Up @@ -58,8 +59,7 @@ GSL_vector::GSL_vector(const GSL_vector& other)

GSL_vector::GSL_vector(GSL_vector&& other) noexcept
{
vec = other.vec;
other.vec = NULL;
move_assign(std::move(other));
}

GSL_vector::~GSL_vector()
Expand Down Expand Up @@ -99,10 +99,8 @@ const GSL_vector& GSL_vector::operator=(const GSL_vector& rhs)

GSL_vector& GSL_vector::operator=(GSL_vector&& rhs)
{
if (this != &rhs) {
vec = rhs.vec;
rhs.vec = NULL;
}
if (this != &rhs)
move_assign(std::move(rhs));

return *this;
}
Expand Down Expand Up @@ -153,6 +151,12 @@ std::ostream& operator<<(std::ostream& ostr, const GSL_vector& vec)
std::cout << ")";
}

void GSL_vector::move_assign(GSL_vector&& other)
{
vec = other.vec;
other.vec = NULL;
}

void GSL_vector::range_check(std::size_t n) const
{
if (!vec)
Expand Down
1 change: 1 addition & 0 deletions src/gsl_vector.hpp
Expand Up @@ -47,6 +47,7 @@ class GSL_vector {
private:
gsl_vector* vec; ///< raw gsl_vector

void move_assign(GSL_vector&&); ///< move assign
void range_check(std::size_t) const;
};

Expand Down

0 comments on commit f93b389

Please sign in to comment.