WopsS / RED4ext.SDK

A library to create mods for REDengine 4 (Cyberpunk 2077), independently of RED4ext.
MIT License
93 stars 31 forks source link

Implement `operator<` for EntityId to be used as hashmap keys #103

Closed MeFisto94 closed 6 months ago

MeFisto94 commented 6 months ago

Description entEntityID.hpp doesn't implement the order operator and as such it can't be used as a key in (hash) maps. Since the intention is clear in every other overload that just delegates to this.hash, this should probably be reflected in this operator, too.

Steps to reproduce if (entityId1 < entityId2) {}

Expected behavior Delegating to the contained hash

Examples

diff --git a/include/RED4ext/Scripting/Natives/entEntityID.hpp b/include/RED4ext/Scripting/Natives/entEntityID.hpp
index ff9f0728..63a11b37 100644
--- a/include/RED4ext/Scripting/Natives/entEntityID.hpp
+++ b/include/RED4ext/Scripting/Natives/entEntityID.hpp
@@ -38,6 +38,11 @@ struct EntityID
         return hash == aRhs.hash;
     }

+    constexpr bool operator<(const EntityID& rhs) const noexcept
+    {
+        return hash < rhs.hash;
+    }
+
     [[nodiscard]] constexpr bool IsDefined() const noexcept
     {
         return hash;