Skip to content

Commit

Permalink
Fix compound assignment operators for vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Apr 18, 2015
1 parent bd25e62 commit 212348d
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/common/math/Vector.h
Expand Up @@ -123,12 +123,12 @@ namespace Math {
Vector<Length, Type> operator/(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a / b;}, other);}

// Compound arithmetic operators
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return *this = *this + other;}
Vector<Length, Type>& operator-=(Vector<Length, Type> other) {return *this = *this - other;}
Vector<Length, Type>& operator*=(Type x) {return *this = *this * x;}
Vector<Length, Type>& operator*=(Vector<Length, Type> other) {return *this = *this * other;}
Vector<Length, Type>& operator/=(Type x) {return *this = *this / x;}
Vector<Length, Type>& operator/=(Vector<Length, Type> other) {return *this = *this / other;}
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) + other;}
Vector<Length, Type>& operator-=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) - other;}
Vector<Length, Type>& operator*=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) * x;}
Vector<Length, Type>& operator*=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) * other;}
Vector<Length, Type>& operator/=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) / x;}
Vector<Length, Type>& operator/=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) / other;}
};
template<size_t Length, typename Type> class VectorOps<Length, Type, typename std::enable_if<std::is_integral<Type>::value>>: public VectorBase<Length, Type> {
public:
Expand All @@ -153,14 +153,14 @@ namespace Math {
Vector<Length, Type> operator%(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a % b;}, other);}

// Compound arithmetic operators
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return *this = *this + other;}
Vector<Length, Type>& operator-=(Vector<Length, Type> other) {return *this = *this - other;}
Vector<Length, Type>& operator*=(Type x) {return *this = *this * x;}
Vector<Length, Type>& operator*=(Vector<Length, Type> other) {return *this = *this * other;}
Vector<Length, Type>& operator/=(Type x) {return *this = *this / x;}
Vector<Length, Type>& operator/=(Vector<Length, Type> other) {return *this = *this / other;}
Vector<Length, Type>& operator%=(Type x) {return *this = *this % x;}
Vector<Length, Type>& operator%=(Vector<Length, Type> other) {return *this = *this % other;}
Vector<Length, Type>& operator+=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) + other;}
Vector<Length, Type>& operator-=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) - other;}
Vector<Length, Type>& operator*=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) * x;}
Vector<Length, Type>& operator*=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) * other;}
Vector<Length, Type>& operator/=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) / x;}
Vector<Length, Type>& operator/=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) / other;}
Vector<Length, Type>& operator%=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) % x;}
Vector<Length, Type>& operator%=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) % other;}

// Bitwise operators
Vector<Length, Type> operator~() const {return this->Apply([](Type a) {return ~a;});}
Expand All @@ -173,13 +173,13 @@ namespace Math {
Vector<Length, Type> operator>>(Vector<Length, Type> other) const {return this->Apply2([](Type a, Type b) {return a >> b;}, other);}

// Compound bitwise operators
Vector<Length, Type>& operator&=(Vector<Length, Type> other) {return *this = *this & other;}
Vector<Length, Type>& operator|=(Vector<Length, Type> other) {return *this = *this | other;}
Vector<Length, Type>& operator^=(Vector<Length, Type> other) {return *this = *this ^ other;}
Vector<Length, Type>& operator<<=(Type x) {return *this = *this << x;}
Vector<Length, Type>& operator<<=(Vector<Length, Type> other) {return *this = *this << other;}
Vector<Length, Type>& operator>>=(Type x) {return *this = *this >> x;}
Vector<Length, Type>& operator>>=(Vector<Length, Type> other) {return *this = *this >> other;}
Vector<Length, Type>& operator&=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) & other;}
Vector<Length, Type>& operator|=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) | other;}
Vector<Length, Type>& operator^=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) ^ other;}
Vector<Length, Type>& operator<<=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) << x;}
Vector<Length, Type>& operator<<=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) << other;}
Vector<Length, Type>& operator>>=(Type x) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) >> x;}
Vector<Length, Type>& operator>>=(Vector<Length, Type> other) {return static_cast<Vector<Length, Type>&>(*this) = static_cast<Vector<Length, Type>&>(*this) >> other;}
};
template<size_t Length> class VectorOps<Length, bool>: public VectorBase<Length, bool> {
public:
Expand All @@ -194,9 +194,9 @@ namespace Math {
Vector<Length, bool> operator^(Vector<Length, bool> other) const {return this->Apply2([](bool a, bool b) {return a != b;}, other);}

// Compound bitwise operators
Vector<Length, bool>& operator&=(Vector<Length, bool> other) {return *this = *this & other;}
Vector<Length, bool>& operator|=(Vector<Length, bool> other) {return *this = *this | other;}
Vector<Length, bool>& operator^=(Vector<Length, bool> other) {return *this = *this ^ other;}
Vector<Length, bool>& operator&=(Vector<Length, bool> other) {return static_cast<Vector<Length, bool>&>(*this) = static_cast<Vector<Length, bool>&>(*this) & other;}
Vector<Length, bool>& operator|=(Vector<Length, bool> other) {return static_cast<Vector<Length, bool>&>(*this) = static_cast<Vector<Length, bool>&>(*this) | other;}
Vector<Length, bool>& operator^=(Vector<Length, bool> other) {return static_cast<Vector<Length, bool>&>(*this) = static_cast<Vector<Length, bool>&>(*this) ^ other;}

// Group testing
bool All() const {return this->Reduce(true, [](bool a, bool b) {return a && b;});}
Expand Down

0 comments on commit 212348d

Please sign in to comment.