public:
Handle() = default;
-
- static Handle from_object(T *o) { Handle h; h.ptr = o; return h; }
+ Handle(nullptr_t) { }
template<typename U>
requires std::is_base_of_v<T, U>
Handle(const Handle<U> &other): ptr(other.ptr) { }
+ static Handle from_object(T *o) { Handle h; h.ptr = o; return h; }
+
T *get() const { return ptr; }
T &operator*() const { return *ptr; }
T *operator->() const { return ptr; }
bool operator==(const Handle &other) const = default;
};
+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