]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/handle.h
Add less-than comparison for handles
[libs/game.git] / source / game / handle.h
index 2e544c7238e75ca7d5418c9f5c7a05c65e61081e..1808654f5e13ee4b60dd05ad633bab1b4249b75d 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GAME_HANDLE_H_
 #define MSP_GAME_HANDLE_H_
 
+#include <functional>
 #include <stdexcept>
 #include "pool.h"
 
@@ -37,8 +38,16 @@ public:
        explicit operator bool() const { return ptr; }
 
        bool operator==(const Handle &other) const = default;
+       bool operator<(const Handle &other) const { return std::less<T *const>()(ptr, other.ptr); }
 };
 
+template<typename T, typename U>
+       requires std::is_base_of_v<U, T>
+Handle<T> dynamic_handle_cast(Handle<U> h)
+{
+       return Handle<T>::from_object(dynamic_cast<T *>(h.get()));
+}
+
 } // namespace Msp::Game
 
 #endif