aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-08-24 11:48:45 +0200
committerShauren <shauren.trinity@gmail.com>2023-08-24 11:48:45 +0200
commit451314241dc40c4e3be600ef95a4f4fbd322f701 (patch)
tree1c55abe5e0027df578a792015254e4b95b8e6d80 /src/server
parent343d09bc95ade0cc34f953b56cbe666baca387fc (diff)
Core/Misc: Modernize comparison operators
(cherry picked from commit f0a862e71bc12d86a898901ef773475a7c964832)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h15
-rw-r--r--src/server/game/Entities/GameObject/GameObjectData.h2
-rw-r--r--src/server/game/Entities/Object/ObjectGuid.h5
-rw-r--r--src/server/game/Entities/Object/Position.h1
-rw-r--r--src/server/game/Globals/ObjectMgr.h7
-rw-r--r--src/server/game/Grids/Cells/Cell.h1
-rw-r--r--src/server/game/Grids/GridDefines.h14
-rw-r--r--src/server/game/Texts/CreatureTextMgr.h5
-rw-r--r--src/server/shared/DataStores/DBCStorageIterator.h1
-rw-r--r--src/server/shared/Dynamic/LinkedList.h28
-rw-r--r--src/server/shared/Realm/Realm.h6
11 files changed, 26 insertions, 59 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index 700fb8638dc..329f9f65de6 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -22,6 +22,7 @@
#include "EnumFlag.h"
#include "ObjectGuid.h"
#include "WaypointDefines.h"
+#include "advstd.h"
#include <limits>
#include <map>
#include <string>
@@ -1578,9 +1579,19 @@ struct SmartScriptHolder
operator bool() const { return entryOrGuid != 0; }
// Default comparision operator using priority field as first ordering field
- bool operator<(SmartScriptHolder const& other) const
+ std::strong_ordering operator<=>(SmartScriptHolder const& right) const
{
- return std::tie(priority, entryOrGuid, source_type, event_id, link) < std::tie(other.priority, other.entryOrGuid, other.source_type, other.event_id, other.link);
+ if (std::strong_ordering cmp = priority <=> right.priority; advstd::is_neq(cmp))
+ return cmp;
+ if (std::strong_ordering cmp = entryOrGuid <=> right.entryOrGuid; advstd::is_neq(cmp))
+ return cmp;
+ if (std::strong_ordering cmp = source_type <=> right.source_type; advstd::is_neq(cmp))
+ return cmp;
+ if (std::strong_ordering cmp = event_id <=> right.event_id; advstd::is_neq(cmp))
+ return cmp;
+ if (std::strong_ordering cmp = link <=> right.link; advstd::is_neq(cmp))
+ return cmp;
+ return std::strong_ordering::equal;
}
static constexpr uint32 DEFAULT_PRIORITY = std::numeric_limits<uint32>::max();
diff --git a/src/server/game/Entities/GameObject/GameObjectData.h b/src/server/game/Entities/GameObject/GameObjectData.h
index 5f68c3f7b16..40eda9ce862 100644
--- a/src/server/game/Entities/GameObject/GameObjectData.h
+++ b/src/server/game/Entities/GameObject/GameObjectData.h
@@ -664,6 +664,8 @@ struct TC_GAME_API QuaternionData
bool isUnit() const;
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) = default;
};
// `gameobject_addon` table
diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h
index 46b23671257..1a6ccb775b2 100644
--- a/src/server/game/Entities/Object/ObjectGuid.h
+++ b/src/server/game/Entities/Object/ObjectGuid.h
@@ -203,9 +203,8 @@ class TC_GAME_API ObjectGuid
TypeID GetTypeId() const { return GetTypeId(GetHigh()); }
bool operator!() const { return IsEmpty(); }
- bool operator==(ObjectGuid const& guid) const { return GetRawValue() == guid.GetRawValue(); }
- bool operator!=(ObjectGuid const& guid) const { return GetRawValue() != guid.GetRawValue(); }
- bool operator< (ObjectGuid const& guid) const { return GetRawValue() < guid.GetRawValue(); }
+ bool operator==(ObjectGuid const& right) const = default;
+ std::strong_ordering operator<=>(ObjectGuid const& right) const = default;
static char const* GetTypeName(HighGuid high);
char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; }
diff --git a/src/server/game/Entities/Object/Position.h b/src/server/game/Entities/Object/Position.h
index d029c270380..69f57b250a1 100644
--- a/src/server/game/Entities/Object/Position.h
+++ b/src/server/game/Entities/Object/Position.h
@@ -62,7 +62,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/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index 8ea3c22213c..35acaed7915 100644
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -77,11 +77,7 @@ struct TempSummonGroupKey
{
}
- bool operator<(TempSummonGroupKey const& rhs) const
- {
- return std::tie(_summonerEntry, _summonerType, _summonGroup) <
- std::tie(rhs._summonerEntry, rhs._summonerType, rhs._summonGroup);
- }
+ std::strong_ordering operator<=>(TempSummonGroupKey const& right) const = default;
private:
uint32 _summonerEntry; ///< Summoner's entry
@@ -608,7 +604,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 cf1337350aa..c5c00d9e366 100644
--- a/src/server/game/Grids/Cells/Cell.h
+++ b/src/server/game/Grids/Cells/Cell.h
@@ -91,7 +91,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 4ba7f33db81..c8560a820f8 100644
--- a/src/server/game/Grids/GridDefines.h
+++ b/src/server/game/Grids/GridDefines.h
@@ -155,22 +155,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/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h
index 263685566aa..fe8450ab797 100644
--- a/src/server/game/Texts/CreatureTextMgr.h
+++ b/src/server/game/Texts/CreatureTextMgr.h
@@ -64,10 +64,7 @@ struct CreatureTextId
{
CreatureTextId(uint32 e, uint32 g, uint32 i) : entry(e), textGroup(g), textId(i) { }
- bool operator<(CreatureTextId const& right) const
- {
- return std::tie(entry, textGroup, textId) < std::tie(right.entry, right.textGroup, right.textId);
- }
+ friend std::strong_ordering operator<=>(CreatureTextId const& left, CreatureTextId const& right) = default;
uint32 entry;
uint32 textGroup;
diff --git a/src/server/shared/DataStores/DBCStorageIterator.h b/src/server/shared/DataStores/DBCStorageIterator.h
index d4ac54bc64c..fce95e09bfa 100644
--- a/src/server/shared/DataStores/DBCStorageIterator.h
+++ b/src/server/shared/DataStores/DBCStorageIterator.h
@@ -45,7 +45,6 @@ public:
T const* operator*() const { return _index[_pos]; }
bool operator==(DBCStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; }
- bool operator!=(DBCStorageIterator const& right) const { return !(*this == right); }
DBCStorageIterator& operator++()
{
diff --git a/src/server/shared/Dynamic/LinkedList.h b/src/server/shared/Dynamic/LinkedList.h
index 0e9e44a2da4..9ace55d1874 100644
--- a/src/server/shared/Dynamic/LinkedList.h
+++ b/src/server/shared/Dynamic/LinkedList.h
@@ -160,7 +160,7 @@ class LinkedListHead
{ // construct with null node pointer
}
- Iterator(pointer _Pnode) : _Ptr(_Pnode)
+ explicit Iterator(pointer _Pnode) : _Ptr(_Pnode)
{ // construct with node pointer _Pnode
}
@@ -206,41 +206,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 fb19bd78d69..75f6fbb13e0 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 <memory>
enum RealmFlags
@@ -42,10 +43,7 @@ struct TC_SHARED_API RealmHandle
uint32 Realm; // primary key in `realmlist` table
- bool operator<(RealmHandle const& r) const
- {
- return Realm < r.Realm;
- }
+ std::strong_ordering operator<=>(RealmHandle const& r) const { return Realm <=> r.Realm; }
};
/// Type of server, this is values from second column of Cfg_Configs.dbc