diff options
Diffstat (limited to 'src')
21 files changed, 77 insertions, 106 deletions
diff --git a/src/common/Cryptography/BigNumber.cpp b/src/common/Cryptography/BigNumber.cpp index 62e459c6dce..35bfc91224d 100644 --- a/src/common/Cryptography/BigNumber.cpp +++ b/src/common/Cryptography/BigNumber.cpp @@ -146,7 +146,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..bbe2bebb42d 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); } + int32 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); } + 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 4d6761780be..3af5fc70a12 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/common/Utilities/Util.h b/src/common/Utilities/Util.h index d37b86f85e5..62c8655b65f 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -417,18 +417,6 @@ public: part[2] = p3; } - inline bool operator<(flag96 const& right) const - { - for (uint8 i = 3; i > 0; --i) - { - if (part[i - 1] < right.part[i - 1]) - return true; - else if (part[i - 1] > right.part[i - 1]) - return false; - } - return false; - } - inline bool operator==(flag96 const& right) const { return diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h index ff2717c9755..4a26e00df52 100644 --- a/src/common/Utilities/advstd.h +++ b/src/common/Utilities/advstd.h @@ -18,9 +18,38 @@ #ifndef TRINITY_ADVSTD_H #define TRINITY_ADVSTD_H +#include <version> + +#ifdef __cpp_lib_bit_cast +#include <bit> +#else +#include <cstring> // for memcpy +#endif +#include <compare> + // this namespace holds implementations of upcoming stdlib features that our c++ version doesn't have yet namespace advstd { +// libc++ is missing these two +[[nodiscard]] constexpr bool is_eq(std::partial_ordering cmp) noexcept { return cmp == 0; } +[[nodiscard]] constexpr bool is_neq(std::partial_ordering cmp) noexcept { return cmp != 0; } + +#ifdef __cpp_lib_bit_cast +using std::bit_cast; +#else +// libstdc++ v10 is missing this +template <typename To, typename From, + std::enable_if_t<std::conjunction_v< + std::bool_constant<sizeof(To) == sizeof(From)>, + std::is_trivially_copyable<To>, + std::is_trivially_copyable<From>>, int> = 0> + [[nodiscard]] constexpr To bit_cast(From const& from) noexcept +{ + To to; + std::memcpy(&to, &from, sizeof(To)); + return to; +} +#endif } #endif 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 diff --git a/src/tools/map_extractor/dbcfile.h b/src/tools/map_extractor/dbcfile.h index 3a92261f1d3..7e0d78e230d 100644 --- a/src/tools/map_extractor/dbcfile.h +++ b/src/tools/map_extractor/dbcfile.h @@ -106,10 +106,6 @@ public: { return record.offset == b.record.offset; } - bool operator!=(Iterator const& b) const - { - return record.offset != b.record.offset; - } private: Record record; diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index 37feda00873..6a421a9106b 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -45,7 +45,7 @@ namespace MMAP uint32 m_mapId; std::set<uint32>* m_tiles; - bool operator==(uint32 id) + bool operator==(uint32 id) const { return m_mapId == id; } diff --git a/src/tools/vmap4_extractor/dbcfile.h b/src/tools/vmap4_extractor/dbcfile.h index 3eee36f0c55..47be107cad6 100644 --- a/src/tools/vmap4_extractor/dbcfile.h +++ b/src/tools/vmap4_extractor/dbcfile.h @@ -123,10 +123,6 @@ public: { return record.offset == b.record.offset; } - bool operator!=(Iterator const& b) const - { - return record.offset != b.record.offset; - } private: Record record; }; |