mirror of https://github.com/OpenTTD/OpenTTD
Codechange: implement operator<=> and remove operators that are synthesized
parent
8fbba84473
commit
760b8f74b7
|
@ -162,19 +162,11 @@ public:
|
|||
|
||||
/* Operators for (in)equality when comparing overflow safe ints. */
|
||||
inline constexpr bool operator == (const OverflowSafeInt& other) const { return this->m_value == other.m_value; }
|
||||
inline constexpr bool operator != (const OverflowSafeInt& other) const { return !(*this == other); }
|
||||
inline constexpr bool operator > (const OverflowSafeInt& other) const { return this->m_value > other.m_value; }
|
||||
inline constexpr bool operator >= (const OverflowSafeInt& other) const { return this->m_value >= other.m_value; }
|
||||
inline constexpr bool operator < (const OverflowSafeInt& other) const { return !(*this >= other); }
|
||||
inline constexpr bool operator <= (const OverflowSafeInt& other) const { return !(*this > other); }
|
||||
inline constexpr auto operator <=>(const OverflowSafeInt& other) const { return this->m_value <=> other.m_value; }
|
||||
|
||||
/* Operators for (in)equality when comparing non-overflow safe ints. */
|
||||
inline constexpr bool operator == (const int other) const { return this->m_value == other; }
|
||||
inline constexpr bool operator != (const int other) const { return !(*this == other); }
|
||||
inline constexpr bool operator > (const int other) const { return this->m_value > other; }
|
||||
inline constexpr bool operator >= (const int other) const { return this->m_value >= other; }
|
||||
inline constexpr bool operator < (const int other) const { return !(*this >= other); }
|
||||
inline constexpr bool operator <= (const int other) const { return !(*this > other); }
|
||||
inline constexpr auto operator <=>(const int other) const { return this->m_value <=> other; }
|
||||
|
||||
inline constexpr operator T () const { return this->m_value; }
|
||||
|
||||
|
|
|
@ -22,20 +22,8 @@ namespace StrongType {
|
|||
friend constexpr bool operator ==(const TType &lhs, const TType &rhs) { return lhs.value == rhs.value; }
|
||||
friend constexpr bool operator ==(const TType &lhs, const TBaseType &rhs) { return lhs.value == rhs; }
|
||||
|
||||
friend constexpr bool operator !=(const TType &lhs, const TType &rhs) { return lhs.value != rhs.value; }
|
||||
friend constexpr bool operator !=(const TType &lhs, const TBaseType &rhs) { return lhs.value != rhs; }
|
||||
|
||||
friend constexpr bool operator <=(const TType &lhs, const TType &rhs) { return lhs.value <= rhs.value; }
|
||||
friend constexpr bool operator <=(const TType &lhs, const TBaseType &rhs) { return lhs.value <= rhs; }
|
||||
|
||||
friend constexpr bool operator <(const TType &lhs, const TType &rhs) { return lhs.value < rhs.value; }
|
||||
friend constexpr bool operator <(const TType &lhs, const TBaseType &rhs) { return lhs.value < rhs; }
|
||||
|
||||
friend constexpr bool operator >=(const TType &lhs, const TType &rhs) { return lhs.value >= rhs.value; }
|
||||
friend constexpr bool operator >=(const TType &lhs, const TBaseType &rhs) { return lhs.value >= rhs; }
|
||||
|
||||
friend constexpr bool operator >(const TType &lhs, const TType &rhs) { return lhs.value > rhs.value; }
|
||||
friend constexpr bool operator >(const TType &lhs, const TBaseType &rhs) { return lhs.value > rhs; }
|
||||
friend constexpr auto operator <=>(const TType &lhs, const TType &rhs) { return lhs.value <=> rhs.value; }
|
||||
friend constexpr auto operator <=>(const TType &lhs, const TBaseType &rhs) { return lhs.value <=> rhs; }
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -117,12 +105,7 @@ namespace StrongType {
|
|||
template <typename TType, typename TBaseType>
|
||||
struct mixin {
|
||||
friend constexpr bool operator ==(const TType &lhs, TCompatibleType rhs) { return lhs.value == static_cast<TBaseType>(rhs); }
|
||||
friend constexpr bool operator !=(const TType &lhs, TCompatibleType rhs) { return lhs.value != static_cast<TBaseType>(rhs); }
|
||||
|
||||
friend constexpr bool operator <=(const TType &lhs, TCompatibleType rhs) { return lhs.value <= static_cast<TBaseType>(rhs); }
|
||||
friend constexpr bool operator <(const TType &lhs, TCompatibleType rhs) { return lhs.value < static_cast<TBaseType>(rhs); }
|
||||
friend constexpr bool operator >=(const TType &lhs, TCompatibleType rhs) { return lhs.value >= static_cast<TBaseType>(rhs); }
|
||||
friend constexpr bool operator >(const TType &lhs, TCompatibleType rhs) { return lhs.value > static_cast<TBaseType>(rhs); }
|
||||
friend constexpr auto operator <=>(const TType &lhs, TCompatibleType rhs) { return lhs.value <=> static_cast<TBaseType>(rhs); }
|
||||
|
||||
friend constexpr TType operator +(const TType &lhs, TCompatibleType rhs) { return TType(lhs.value + rhs); }
|
||||
friend constexpr TType operator -(const TType &lhs, TCompatibleType rhs) { return TType(lhs.value - rhs); }
|
||||
|
|
|
@ -150,23 +150,14 @@ public:
|
|||
{
|
||||
return const_cast<NetworkAddress*>(this)->CompareTo(address) == 0;
|
||||
}
|
||||
/**
|
||||
* Compare the address of this class with the address of another.
|
||||
* @param address the other address.
|
||||
* @return true if both do not match.
|
||||
*/
|
||||
bool operator != (NetworkAddress address) const
|
||||
{
|
||||
return const_cast<NetworkAddress*>(this)->CompareTo(address) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the address of this class with the address of another.
|
||||
* @param address the other address.
|
||||
*/
|
||||
bool operator < (NetworkAddress &address)
|
||||
auto operator <=>(NetworkAddress &address)
|
||||
{
|
||||
return this->CompareTo(address) < 0;
|
||||
return this->CompareTo(address) <=> 0;
|
||||
}
|
||||
|
||||
void Listen(int socktype, SocketList *sockets);
|
||||
|
|
Loading…
Reference in New Issue