diff options
23 files changed, 55 insertions, 180 deletions
diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index 6839cbc9255..b9f6a1c947c 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -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); } diff --git a/src/common/Cryptography/BigNumber.h b/src/common/Cryptography/BigNumber.h index e61a8073c31..d36c8a9f718 100644 --- a/src/common/Cryptography/BigNumber.h +++ b/src/common/Cryptography/BigNumber.h @@ -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; diff --git a/src/common/Debugging/WheatyExceptionReport.h b/src/common/Debugging/WheatyExceptionReport.h index 2b99dcbb83c..b1876528a78 100644 --- a/src/common/Debugging/WheatyExceptionReport.h +++ b/src/common/Debugging/WheatyExceptionReport.h @@ -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; diff --git a/src/common/Utilities/SmartEnum.h b/src/common/Utilities/SmartEnum.h index 24e3c60bd30..3c58d433406 100644 --- a/src/common/Utilities/SmartEnum.h +++ b/src/common/Utilities/SmartEnum.h @@ -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); } diff --git a/src/common/Utilities/TaskScheduler.h b/src/common/Utilities/TaskScheduler.h index ee43a203a13..aee387ea46f 100644 --- a/src/common/Utilities/TaskScheduler.h +++ b/src/common/Utilities/TaskScheduler.h @@ -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 diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index f1ad527b489..bdaa0516339 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -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; diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.h b/src/server/game/Battlegrounds/BattlegroundMgr.h index 8de23069e99..836ca705dc3 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.h +++ b/src/server/game/Battlegrounds/BattlegroundMgr.h @@ -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; diff --git a/src/server/game/Chat/LanguageMgr.h b/src/server/game/Chat/LanguageMgr.h index fda88cb2972..9a8ea6ceed0 100644 --- a/src/server/game/Chat/LanguageMgr.h +++ b/src/server/game/Chat/LanguageMgr.h @@ -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; diff --git a/src/server/game/Entities/AreaTrigger/AreaTriggerTemplate.h b/src/server/game/Entities/AreaTrigger/AreaTriggerTemplate.h index fdccc07a420..3b5e287077e 100644 --- a/src/server/game/Entities/AreaTrigger/AreaTriggerTemplate.h +++ b/src/server/game/Entities/AreaTrigger/AreaTriggerTemplate.h @@ -79,6 +79,8 @@ struct AreaTriggerId { uint32 Id = 0; bool IsServerSide = false; + + friend bool operator==(AreaTriggerId const& left, AreaTriggerId const& right) = default; }; struct AreaTriggerAction diff --git a/src/server/game/Entities/GameObject/QuaternionData.h b/src/server/game/Entities/GameObject/QuaternionData.h index cf806ac6cba..2d0f52a7d49 100644 --- a/src/server/game/Entities/GameObject/QuaternionData.h +++ b/src/server/game/Entities/GameObject/QuaternionData.h @@ -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__ diff --git a/src/server/game/Entities/Object/Position.h b/src/server/game/Entities/Object/Position.h index ad5dc5a390a..d8b69246b1b 100644 --- a/src/server/game/Entities/Object/Position.h +++ b/src/server/game/Entities/Object/Position.h @@ -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; } diff --git a/src/server/game/Globals/AreaTriggerDataStore.cpp b/src/server/game/Globals/AreaTriggerDataStore.cpp index c412c0ce5ce..d3f5a843484 100644 --- a/src/server/game/Globals/AreaTriggerDataStore.cpp +++ b/src/server/game/Globals/AreaTriggerDataStore.cpp @@ -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 { diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 5b3a7d2122c..3a9bf626ca9 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -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; } diff --git a/src/server/game/Grids/Cells/Cell.h b/src/server/game/Grids/Cells/Cell.h index a979a9fe007..e2acd942015 100644 --- a/src/server/game/Grids/Cells/Cell.h +++ b/src/server/game/Grids/Cells/Cell.h @@ -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 diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 32a81b968fb..ce5ca7614c3 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -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; diff --git a/src/server/game/Miscellaneous/SharedDefines.h b/src/server/game/Miscellaneous/SharedDefines.h index b7d593bab39..4c6cac27059 100644 --- a/src/server/game/Miscellaneous/SharedDefines.h +++ b/src/server/game/Miscellaneous/SharedDefines.h @@ -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 }; diff --git a/src/server/game/Phasing/PhaseShift.h b/src/server/game/Phasing/PhaseShift.h index 89f5ad98896..5c26f0c1a91 100644 --- a/src/server/game/Phasing/PhaseShift.h +++ b/src/server/game/Phasing/PhaseShift.h @@ -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); } }; diff --git a/src/server/game/Server/Packets/ItemPacketsCommon.cpp b/src/server/game/Server/Packets/ItemPacketsCommon.cpp index 70da5777d07..0843a4091e8 100644 --- a/src/server/game/Server/Packets/ItemPacketsCommon.cpp +++ b/src/server/game/Server/Packets/ItemPacketsCommon.cpp @@ -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; - - 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; +bool ItemInstance::operator==(ItemInstance const& r) const = default; - if (Modifications != right.Modifications) - return false; - - return true; -} +bool ItemBonusKey::operator==(ItemBonusKey const& right) const = default; ByteBuffer& operator<<(ByteBuffer& data, ItemBonuses const& itemBonusInstanceData) { diff --git a/src/server/game/Server/Packets/ItemPacketsCommon.h b/src/server/game/Server/Packets/ItemPacketsCommon.h index b70cb8b1491..a9fb6ce95ce 100644 --- a/src/server/game/Server/Packets/ItemPacketsCommon.h +++ b/src/server/game/Server/Packets/ItemPacketsCommon.h @@ -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 diff --git a/src/server/shared/DataStores/DBStorageIterator.h b/src/server/shared/DataStores/DBStorageIterator.h index 109acac6779..6df777c76c9 100644 --- a/src/server/shared/DataStores/DBStorageIterator.h +++ b/src/server/shared/DataStores/DBStorageIterator.h @@ -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++() { diff --git a/src/server/shared/Dynamic/LinkedList.h b/src/server/shared/Dynamic/LinkedList.h index ce1fb314329..b32710910a9 100644 --- a/src/server/shared/Dynamic/LinkedList.h +++ b/src/server/shared/Dynamic/LinkedList.h @@ -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 }; diff --git a/src/server/shared/Realm/Realm.h b/src/server/shared/Realm/Realm.h index a51f4550051..9dcbb581538 100644 --- a/src/server/shared/Realm/Realm.h +++ b/src/server/shared/Realm/Realm.h @@ -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; diff --git a/src/tools/vmap4_assembler/TileAssembler.h b/src/tools/vmap4_assembler/TileAssembler.h index 490dc3b964c..73b58941de4 100644 --- a/src/tools/vmap4_assembler/TileAssembler.h +++ b/src/tools/vmap4_assembler/TileAssembler.h @@ -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 |