Core/Misc: Modernize comparison operators

This commit is contained in:
Shauren
2023-08-24 00:51:26 +02:00
parent f108a50abf
commit f0a862e71b
23 changed files with 55 additions and 180 deletions

View File

@@ -132,7 +132,7 @@ BigNumber& BigNumber::operator<<=(int n)
return *this;
}
int BigNumber::CompareTo(BigNumber const& bn) const
int32 BigNumber::CompareTo(BigNumber const& bn) const
{
return BN_cmp(_bn, bn._bn);
}

View File

@@ -94,12 +94,17 @@ class TC_COMMON_API BigNumber
return t <<= n;
}
int CompareTo(BigNumber const& bn) const;
bool operator<=(BigNumber const& bn) const { return (CompareTo(bn) <= 0); }
bool operator==(BigNumber const& bn) const { return (CompareTo(bn) == 0); }
bool operator>=(BigNumber const& bn) const { return (CompareTo(bn) >= 0); }
bool operator<(BigNumber const& bn) const { return (CompareTo(bn) < 0); }
bool operator>(BigNumber const& bn) const { return (CompareTo(bn) > 0); }
int32 CompareTo(BigNumber const& bn) const;
bool operator==(BigNumber const& bn) const { return CompareTo(bn) == 0; }
std::strong_ordering operator<=>(BigNumber const& other) const
{
int32 cmp = CompareTo(other);
if (cmp < 0)
return std::strong_ordering::less;
if (cmp > 0)
return std::strong_ordering::greater;
return std::strong_ordering::equal;
}
bool IsZero() const;
bool IsNegative() const;

View File

@@ -7,6 +7,7 @@
#include <winnt.h>
#include <winternl.h>
#include <dbghelp.h>
#include <compare>
#include <set>
#include <cstdlib>
#include <cstdio>
@@ -101,11 +102,8 @@ struct SymbolPair
_offset = offset;
}
bool operator<(SymbolPair const& other) const
{
return _offset < other._offset ||
(_offset == other._offset && _type < other._type);
}
bool operator==(SymbolPair const& other) const = default;
std::strong_ordering operator<=>(SymbolPair const& other) const = default;
DWORD _type;
DWORD_PTR _offset;

View File

@@ -85,13 +85,10 @@ class EnumUtils
Iterator() : _index(EnumUtils::Count<Enum>()) {}
explicit Iterator(size_t index) : _index(index) { }
bool operator==(const Iterator& other) const { return other._index == _index; }
bool operator!=(const Iterator& other) const { return !operator==(other); }
bool operator==(const Iterator& other) const = default;
std::strong_ordering operator<=>(const Iterator& other) const = default;
difference_type operator-(Iterator const& other) const { return _index - other._index; }
bool operator<(const Iterator& other) const { return _index < other._index; }
bool operator<=(const Iterator& other) const { return _index <= other._index; }
bool operator>(const Iterator& other) const { return _index > other._index; }
bool operator>=(const Iterator& other) const { return _index >= other._index; }
value_type operator[](difference_type d) const { return FromIndex<Enum>(_index + d); }
value_type operator*() const { return operator[](0); }

View File

@@ -95,18 +95,13 @@ class TC_COMMON_API TaskScheduler
Task& operator= (Task&& right) = delete;
// Order tasks by its end
inline bool operator< (Task const& other) const
std::weak_ordering operator<=> (Task const& other) const
{
return _end < other._end;
}
inline bool operator> (Task const& other) const
{
return _end > other._end;
return _end <=> other._end;
}
// Compare tasks with its end
inline bool operator== (Task const& other)
bool operator== (Task const& other) const
{
return _end == other._end;
}
@@ -126,7 +121,7 @@ class TC_COMMON_API TaskScheduler
bool operator() (TaskContainer const& left, TaskContainer const& right) const
{
return (*left.get()) < (*right.get());
};
}
};
class TC_COMMON_API TaskQueue

View File

@@ -165,18 +165,7 @@ struct AuctionsBucketKey
uint16 BattlePetSpeciesId;
uint16 SuffixItemNameDescriptionId;
bool operator==(AuctionsBucketKey const& right) const
{
return ItemId == right.ItemId
&& ItemLevel == right.ItemLevel
&& BattlePetSpeciesId == right.BattlePetSpeciesId
&& SuffixItemNameDescriptionId == right.SuffixItemNameDescriptionId;
}
bool operator!=(AuctionsBucketKey const& right) const
{
return !(*this == right);
}
bool operator==(AuctionsBucketKey const& right) const = default;
friend std::strong_ordering operator<=>(AuctionsBucketKey const& left, AuctionsBucketKey const& right) = default;

View File

@@ -164,10 +164,7 @@ class TC_GAME_API BattlegroundMgr
BattlegroundQueueTypeId QueueId;
BattlegroundBracketId BracketId;
bool operator==(ScheduledQueueUpdate const& right) const
{
return ArenaMatchmakerRating == right.ArenaMatchmakerRating && QueueId == right.QueueId && BracketId == right.BracketId;
}
bool operator==(ScheduledQueueUpdate const& right) const = default;
};
std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;

View File

@@ -30,10 +30,7 @@ struct LanguageDesc
uint32 SpellId = 0;
uint32 SkillId = 0;
friend bool operator==(LanguageDesc const& left, LanguageDesc const& right)
{
return left.SpellId == right.SpellId && left.SkillId == right.SkillId;
}
friend bool operator==(LanguageDesc const& left, LanguageDesc const& right) = default;
};
struct SpellEffectEntry;

View File

@@ -79,6 +79,8 @@ struct AreaTriggerId
{
uint32 Id = 0;
bool IsServerSide = false;
friend bool operator==(AreaTriggerId const& left, AreaTriggerId const& right) = default;
};
struct AreaTriggerAction

View File

@@ -35,15 +35,7 @@ struct TC_GAME_API QuaternionData
void toEulerAnglesZYX(float& Z, float& Y, float& X) const;
static QuaternionData fromEulerAnglesZYX(float Z, float Y, float X);
friend bool operator==(QuaternionData const& left, QuaternionData const& right)
{
return left.x == right.x && left.y == right.y && left.z == right.z && left.w == right.w;
}
friend bool operator!=(QuaternionData const& left, QuaternionData const& right)
{
return !(left == right);
}
friend bool operator==(QuaternionData const& left, QuaternionData const& right) = default;
};
#endif // QuaternionData_h__

View File

@@ -59,7 +59,6 @@ private:
public:
bool operator==(Position const& a) const;
bool operator!=(Position const& a) const { return !(operator==(a)); }
void Relocate(float x, float y) { m_positionX = x; m_positionY = y; }
void Relocate(float x, float y, float z) { Relocate(x, y); m_positionZ = z; }

View File

@@ -27,25 +27,17 @@
#include "Timer.h"
#include <cmath>
bool operator==(AreaTriggerId const& left, AreaTriggerId const& right)
template <>
struct std::hash<AreaTriggerId>
{
return left.Id == right.Id && left.IsServerSide == right.IsServerSide;
}
namespace std
{
template <>
struct hash<AreaTriggerId>
std::size_t operator()(AreaTriggerId const& value) const noexcept
{
std::size_t operator()(AreaTriggerId const& value) const noexcept
{
size_t hashVal = 0;
Trinity::hash_combine(hashVal, value.Id);
Trinity::hash_combine(hashVal, value.IsServerSide);
return hashVal;
}
};
}
size_t hashVal = 0;
Trinity::hash_combine(hashVal, value.Id);
Trinity::hash_combine(hashVal, value.IsServerSide);
return hashVal;
}
};
namespace
{

View File

@@ -578,7 +578,6 @@ struct QuestRelationResult
}
bool operator==(Iterator const& other) const { return _it == other._it; }
bool operator!=(Iterator const& other) const { return _it != other._it; }
Iterator& operator++() { ++_it; skip(); return *this; }
Iterator operator++(int) { Iterator t = *this; ++*this; return t; }

View File

@@ -89,7 +89,6 @@ struct Cell
}
bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
bool operator != (Cell const& cell) const { return !operator == (cell); }
union
{
struct

View File

@@ -168,22 +168,12 @@ struct CoordPair
return y_coord * LIMIT + x_coord;
}
friend bool operator==(CoordPair const& p1, CoordPair const& p2) = default;
uint32 x_coord;
uint32 y_coord;
};
template<uint32 LIMIT>
bool operator==(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2)
{
return (p1.x_coord == p2.x_coord && p1.y_coord == p2.y_coord);
}
template<uint32 LIMIT>
bool operator!=(const CoordPair<LIMIT> &p1, const CoordPair<LIMIT> &p2)
{
return !(p1 == p2);
}
typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridCoord;
typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellCoord;

View File

@@ -20,6 +20,7 @@
#include "Define.h"
#include "EnumFlag.h"
#include <compare>
float const GROUND_HEIGHT_TOLERANCE = 0.05f; // Extra tolerance to z position to check if it is in air or on ground.
constexpr float Z_OFFSET_FIND_HEIGHT = 0.5f;
@@ -6566,29 +6567,9 @@ struct BattlegroundQueueTypeId
| UI64LIT(0x1F10000000000000);
}
constexpr bool operator==(BattlegroundQueueTypeId right) const
{
return BattlemasterListId == right.BattlemasterListId
&& Type == right.Type
&& Rated == right.Rated
&& TeamSize == right.TeamSize;
}
constexpr bool operator==(BattlegroundQueueTypeId const& right) const = default;
constexpr bool operator!=(BattlegroundQueueTypeId right) const
{
return !(*this == right);
}
constexpr bool operator<(BattlegroundQueueTypeId right) const
{
if (BattlemasterListId != right.BattlemasterListId)
return BattlemasterListId < right.BattlemasterListId;
if (Type != right.Type)
return Type < right.Type;
if (Rated != right.Rated)
return Rated < right.Rated;
return TeamSize < right.TeamSize;
}
constexpr std::strong_ordering operator<=>(BattlegroundQueueTypeId const& right) const = default;
};
constexpr BattlegroundQueueTypeId BATTLEGROUND_QUEUE_NONE = { 0, 0, false, 0 };

View File

@@ -63,7 +63,7 @@ public:
EnumFlag<PhaseFlags> Flags;
int32 References;
std::vector<Condition*> const* AreaConditions;
bool operator<(PhaseRef const& right) const { return Id < right.Id; }
std::strong_ordering operator<=>(PhaseRef const& right) const { return Id <=> right.Id; }
bool operator==(PhaseRef const& right) const { return Id == right.Id; }
bool IsPersonal() const { return Flags.HasFlag(PhaseFlags::Personal); }
};

View File

@@ -33,10 +33,7 @@ bool ItemBonuses::operator==(ItemBonuses const& r) const
return std::is_permutation(BonusListIDs.begin(), BonusListIDs.end(), r.BonusListIDs.begin());
}
bool ItemMod::operator==(ItemMod const& r) const
{
return Value == r.Value && Type == r.Type;
}
bool ItemMod::operator==(ItemMod const& r) const = default;
bool ItemModList::operator==(ItemModList const& r) const
{
@@ -107,36 +104,9 @@ void ItemInstance::Initialize(::VoidStorageItem const* voidItem)
}
}
bool ItemInstance::operator==(ItemInstance const& r) const
{
if (ItemID != r.ItemID)
return false;
bool ItemInstance::operator==(ItemInstance const& r) const = default;
if (ItemBonus.has_value() != r.ItemBonus.has_value())
return false;
if (Modifications != r.Modifications)
return false;
if (ItemBonus.has_value() && *ItemBonus != *r.ItemBonus)
return false;
return true;
}
bool ItemBonusKey::operator==(ItemBonusKey const& right) const
{
if (ItemID != right.ItemID)
return false;
if (BonusListIDs != right.BonusListIDs)
return false;
if (Modifications != right.Modifications)
return false;
return true;
}
bool ItemBonusKey::operator==(ItemBonusKey const& right) const = default;
ByteBuffer& operator<<(ByteBuffer& data, ItemBonuses const& itemBonusInstanceData)
{

View File

@@ -44,7 +44,6 @@ namespace WorldPackets
std::vector<int32> BonusListIDs;
bool operator==(ItemBonuses const& r) const;
bool operator!=(ItemBonuses const& r) const { return !(*this == r); }
};
struct ItemMod
@@ -56,7 +55,6 @@ namespace WorldPackets
ItemModifier Type = MAX_ITEM_MODIFIERS;
bool operator==(ItemMod const& r) const;
bool operator!=(ItemMod const& r) const { return !(*this == r); }
};
struct ItemModList
@@ -64,7 +62,6 @@ namespace WorldPackets
Array<ItemMod, MAX_ITEM_MODIFIERS> Values;
bool operator==(ItemModList const& r) const;
bool operator!=(ItemModList const& r) const { return !(*this == r); }
};
struct ItemInstance
@@ -79,7 +76,6 @@ namespace WorldPackets
ItemModList Modifications;
bool operator==(ItemInstance const& r) const;
bool operator!=(ItemInstance const& r) const { return !(*this == r); }
};
struct ItemBonusKey
@@ -89,7 +85,6 @@ namespace WorldPackets
std::vector<ItemMod> Modifications;
bool operator==(ItemBonusKey const& right) const;
bool operator!=(ItemBonusKey const& r) const { return !(*this == r); }
};
struct ItemEnchantData

View File

@@ -45,7 +45,6 @@ public:
T const* operator*() const { return _index[_pos]; }
bool operator==(DBStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; }
bool operator!=(DBStorageIterator const& right) const { return !(*this == right); }
DBStorageIterator& operator++()
{

View File

@@ -162,7 +162,7 @@ class LinkedListHead
{ // construct with null node pointer
}
Iterator(pointer _Pnode) : _Ptr(_Pnode)
explicit Iterator(pointer _Pnode) : _Ptr(_Pnode)
{ // construct with node pointer _Pnode
}
@@ -208,41 +208,19 @@ class LinkedListHead
return (_Tmp);
}
bool operator==(Iterator const& _Right) const
{ // test for iterator equality
return (_Ptr == _Right._Ptr);
}
bool operator!=(Iterator const& _Right) const
{ // test for iterator inequality
return (!(*this == _Right));
}
bool operator==(Iterator const& _Right) const = default;
// test for iterator equality
bool operator==(pointer const& _Right) const
{ // test for pointer equality
return (_Ptr != _Right);
}
bool operator!=(pointer const& _Right) const
{ // test for pointer equality
return (!(*this == _Right));
}
bool operator==(const_reference _Right) const
{ // test for reference equality
return (_Ptr == &_Right);
}
bool operator!=(const_reference _Right) const
{ // test for reference equality
return (_Ptr != &_Right);
}
pointer _Mynode()
{ // return node pointer
return (_Ptr);
}
protected:
pointer _Ptr; // pointer to node
};

View File

@@ -20,6 +20,7 @@
#include "Common.h"
#include "AsioHacksFwd.h"
#include <compare>
#include <vector>
enum RealmFlags
@@ -48,10 +49,9 @@ namespace Battlenet
uint8 Site;
uint32 Realm; // primary key in `realmlist` table
bool operator<(RealmHandle const& r) const
{
return Realm < r.Realm;
}
bool operator==(RealmHandle const& r) const { return Realm == r.Realm; }
std::strong_ordering operator<=>(RealmHandle const& r) const { return Realm <=> r.Realm; }
uint32 GetAddress() const { return (Region << 24) | (Site << 16) | uint16(Realm); }
std::string GetAddressString() const;

View File

@@ -20,6 +20,7 @@
#include <G3D/Vector3.h>
#include <G3D/Matrix3.h>
#include <compare>
#include <deque>
#include <map>
#include <set>
@@ -60,7 +61,7 @@ namespace VMAP
uint32 Id;
uint32 Flags;
bool operator<(TileSpawn const& right) const { return Id < right.Id; }
std::strong_ordering operator<=>(TileSpawn const& right) const { return Id <=> right.Id; }
};
struct MapSpawns