From eaab9bb5ad98b2ef5987698cc5fc7eb7e39ee7b2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 18 Jun 2023 00:58:32 +0300 Subject: [PATCH] Add a dynamic cast function for Owned --- source/game/owned.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/game/owned.h b/source/game/owned.h index 9b9d99c..e51244d 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -18,6 +18,9 @@ class Owned: public Handle template friend class Owned; + template + friend Owned dynamic_owned_cast(Owned &&); + public: Owned() = default; @@ -141,6 +144,20 @@ void Owned::destroy() pool.destroy(this->ptr); } + +template +Owned dynamic_owned_cast(Owned &&src) +{ + T *ptr = dynamic_cast(src.get()); + if(!ptr) + return Owned(); + + Owned result; + result.ptr = ptr; + src.ptr = nullptr; + return result; +} + } // namespace Msp::Game #endif -- 2.45.2