summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-05-13 21:30:23 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-05-13 23:22:48 +0100
commit11528e45e95972e5d5b0fcdeb8f3731fd97dc79d (patch)
treedaf08ac9ddd2444411c2e85f6548372e1bce89ec
parent15b26fd06ca38de2b7752ed3a6d68f149cdd4f21 (diff)
Use friend functions rather than methods for StronglyTypedNumber binary ops
-rw-r--r--src/units.hh44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/units.hh b/src/units.hh
index 2ef536d2..21c583b2 100644
--- a/src/units.hh
+++ b/src/units.hh
@@ -21,20 +21,20 @@ public:
}
[[gnu::always_inline]]
- constexpr RealType operator+(RealType other) const
- { return RealType(m_value + other.m_value); }
+ constexpr friend RealType operator+(RealType lhs, RealType rhs)
+ { return RealType(lhs.m_value + rhs.m_value); }
[[gnu::always_inline]]
- constexpr RealType operator-(RealType other) const
- { return RealType(m_value - other.m_value); }
+ constexpr friend RealType operator-(RealType lhs, RealType rhs)
+ { return RealType(lhs.m_value - rhs.m_value); }
[[gnu::always_inline]]
- constexpr RealType operator*(RealType other) const
- { return RealType(m_value * other.m_value); }
+ constexpr friend RealType operator*(RealType lhs, RealType rhs)
+ { return RealType(lhs.m_value * rhs.m_value); }
[[gnu::always_inline]]
- constexpr RealType operator/(RealType other) const
- { return RealType(m_value / other.m_value); }
+ constexpr friend RealType operator/(RealType lhs, RealType rhs)
+ { return RealType(lhs.m_value / rhs.m_value); }
[[gnu::always_inline]]
RealType& operator+=(RealType other)
@@ -72,36 +72,36 @@ public:
constexpr RealType operator-() const { return RealType(-m_value); }
[[gnu::always_inline]]
- constexpr RealType operator%(RealType other) const
- { return RealType(m_value % other.m_value); }
+ constexpr friend RealType operator%(RealType lhs, RealType rhs)
+ { return RealType(lhs.m_value % rhs.m_value); }
[[gnu::always_inline]]
RealType& operator%=(RealType other)
{ m_value %= other.m_value; return static_cast<RealType&>(*this); }
[[gnu::always_inline]]
- constexpr bool operator==(RealType other) const
- { return m_value == other.m_value; }
+ constexpr friend bool operator==(RealType lhs, RealType rhs)
+ { return lhs.m_value == rhs.m_value; }
[[gnu::always_inline]]
- constexpr bool operator!=(RealType other) const
- { return m_value != other.m_value; }
+ constexpr friend bool operator!=(RealType lhs, RealType rhs)
+ { return lhs.m_value != rhs.m_value; }
[[gnu::always_inline]]
- constexpr bool operator<(RealType other) const
- { return m_value < other.m_value; }
+ constexpr friend bool operator<(RealType lhs, RealType rhs)
+ { return lhs.m_value < rhs.m_value; }
[[gnu::always_inline]]
- constexpr bool operator<=(RealType other) const
- { return m_value <= other.m_value; }
+ constexpr friend bool operator<=(RealType lhs, RealType rhs)
+ { return lhs.m_value <= rhs.m_value; }
[[gnu::always_inline]]
- constexpr bool operator>(RealType other) const
- { return m_value > other.m_value; }
+ constexpr friend bool operator>(RealType lhs, RealType rhs)
+ { return lhs.m_value > rhs.m_value; }
[[gnu::always_inline]]
- constexpr bool operator>=(RealType other) const
- { return m_value >= other.m_value; }
+ constexpr friend bool operator>=(RealType lhs, RealType rhs)
+ { return lhs.m_value >= rhs.m_value; }
[[gnu::always_inline]]
constexpr bool operator!() const