From 0948a33396b0ebe39cd2f4cbfcb78919a533229f Mon Sep 17 00:00:00 2001 From: MaciejDziuban Date: Mon, 17 Feb 2020 22:57:58 +0100 Subject: [PATCH] Add move semantics to vector classes --- src/mathematics/Vector2.h | 11 +++++++++++ src/mathematics/Vector3.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/mathematics/Vector2.h b/src/mathematics/Vector2.h index cefeb561..282a70fc 100644 --- a/src/mathematics/Vector2.h +++ b/src/mathematics/Vector2.h @@ -62,6 +62,9 @@ struct Vector2 { /// Copy-constructor Vector2(const Vector2& vector); + /// Move-constructor + Vector2(Vector2&& vector) noexcept; + /// Destructor ~Vector2() = default; @@ -131,6 +134,9 @@ struct Vector2 { /// Overloaded operator Vector2& operator=(const Vector2& vector); + /// Overloaded move-assignment operator + Vector2& operator=(Vector2&& vector) noexcept; + /// Overloaded less than operator for ordering to be used inside std::set for instance bool operator<(const Vector2& vector) const; @@ -173,6 +179,8 @@ inline Vector2::Vector2(const Vector2& vector) : x(vector.x), y(vector.y) { } +/// Move-constructor +inline Vector2::Vector2(Vector2&& vector) noexcept = default; // Set the vector to zero inline void Vector2::setToZero() { @@ -337,6 +345,9 @@ inline Vector2& Vector2::operator=(const Vector2& vector) { return *this; } +/// Move-assignment operator +inline Vector2& Vector2::operator=(Vector2&& vector) noexcept = default; + // Overloaded less than operator for ordering to be used inside std::set for instance inline bool Vector2::operator<(const Vector2& vector) const { return (x == vector.x ? y < vector.y : x < vector.x); diff --git a/src/mathematics/Vector3.h b/src/mathematics/Vector3.h index e0fd7ce3..2edc2ad9 100644 --- a/src/mathematics/Vector3.h +++ b/src/mathematics/Vector3.h @@ -65,6 +65,9 @@ struct Vector3 { /// Copy-constructor Vector3(const Vector3& vector); + /// Move-constructor + Vector3(Vector3&& vector) noexcept; + /// Destructor ~Vector3() = default; @@ -143,6 +146,9 @@ struct Vector3 { /// Overloaded operator Vector3& operator=(const Vector3& vector); + /// Overloaded move-assignment operator + Vector3& operator=(Vector3&& vector) noexcept; + /// Overloaded less than operator for ordering to be used inside std::set for instance bool operator<(const Vector3& vector) const; @@ -185,6 +191,9 @@ inline Vector3::Vector3(const Vector3& vector) : x(vector.x), y(vector.y), z(vec } +/// Move-constructor +inline Vector3::Vector3(Vector3&& vector) noexcept = default; + // Set the vector to zero inline void Vector3::setToZero() { x = 0; @@ -364,6 +373,9 @@ inline Vector3& Vector3::operator=(const Vector3& vector) { return *this; } +// Move-assignment operator +inline Vector3& Vector3::operator=(Vector3&& vector) noexcept = default; + // Overloaded less than operator for ordering to be used inside std::set for instance inline bool Vector3::operator<(const Vector3& vector) const { return (x == vector.x ? (y == vector.y ? z < vector.z : y < vector.y) : x < vector.x);