aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities
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/common/Utilities
parent343d09bc95ade0cc34f953b56cbe666baca387fc (diff)
Core/Misc: Modernize comparison operators
(cherry picked from commit f0a862e71bc12d86a898901ef773475a7c964832)
Diffstat (limited to 'src/common/Utilities')
-rw-r--r--src/common/Utilities/SmartEnum.h9
-rw-r--r--src/common/Utilities/TaskScheduler.h13
-rw-r--r--src/common/Utilities/Util.h12
-rw-r--r--src/common/Utilities/advstd.h29
4 files changed, 36 insertions, 27 deletions
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