Use friend functions rather than methods for StronglyTypedNumber binary ops
This commit is contained in:
parent
15b26fd06c
commit
11528e45e9
44
src/units.hh
44
src/units.hh
|
@ -21,20 +21,20 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator+(RealType other) const
|
constexpr friend RealType operator+(RealType lhs, RealType rhs)
|
||||||
{ return RealType(m_value + other.m_value); }
|
{ return RealType(lhs.m_value + rhs.m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator-(RealType other) const
|
constexpr friend RealType operator-(RealType lhs, RealType rhs)
|
||||||
{ return RealType(m_value - other.m_value); }
|
{ return RealType(lhs.m_value - rhs.m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator*(RealType other) const
|
constexpr friend RealType operator*(RealType lhs, RealType rhs)
|
||||||
{ return RealType(m_value * other.m_value); }
|
{ return RealType(lhs.m_value * rhs.m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator/(RealType other) const
|
constexpr friend RealType operator/(RealType lhs, RealType rhs)
|
||||||
{ return RealType(m_value / other.m_value); }
|
{ return RealType(lhs.m_value / rhs.m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
RealType& operator+=(RealType other)
|
RealType& operator+=(RealType other)
|
||||||
|
@ -72,36 +72,36 @@ public:
|
||||||
constexpr RealType operator-() const { return RealType(-m_value); }
|
constexpr RealType operator-() const { return RealType(-m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr RealType operator%(RealType other) const
|
constexpr friend RealType operator%(RealType lhs, RealType rhs)
|
||||||
{ return RealType(m_value % other.m_value); }
|
{ return RealType(lhs.m_value % rhs.m_value); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
RealType& operator%=(RealType other)
|
RealType& operator%=(RealType other)
|
||||||
{ m_value %= other.m_value; return static_cast<RealType&>(*this); }
|
{ m_value %= other.m_value; return static_cast<RealType&>(*this); }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator==(RealType other) const
|
constexpr friend bool operator==(RealType lhs, RealType rhs)
|
||||||
{ return m_value == other.m_value; }
|
{ return lhs.m_value == rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator!=(RealType other) const
|
constexpr friend bool operator!=(RealType lhs, RealType rhs)
|
||||||
{ return m_value != other.m_value; }
|
{ return lhs.m_value != rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator<(RealType other) const
|
constexpr friend bool operator<(RealType lhs, RealType rhs)
|
||||||
{ return m_value < other.m_value; }
|
{ return lhs.m_value < rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator<=(RealType other) const
|
constexpr friend bool operator<=(RealType lhs, RealType rhs)
|
||||||
{ return m_value <= other.m_value; }
|
{ return lhs.m_value <= rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator>(RealType other) const
|
constexpr friend bool operator>(RealType lhs, RealType rhs)
|
||||||
{ return m_value > other.m_value; }
|
{ return lhs.m_value > rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator>=(RealType other) const
|
constexpr friend bool operator>=(RealType lhs, RealType rhs)
|
||||||
{ return m_value >= other.m_value; }
|
{ return lhs.m_value >= rhs.m_value; }
|
||||||
|
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr bool operator!() const
|
constexpr bool operator!() const
|
||||||
|
|
Loading…
Reference in New Issue
Block a user