From: Mikko Rasa Date: Mon, 15 May 2023 20:38:13 +0000 (+0300) Subject: Allow clearing an Owned by assigning nullptr X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=544e535b6e9a4162fa7dd8d2645f7e7d720c9a88;p=libs%2Fgame.git Allow clearing an Owned by assigning nullptr --- diff --git a/source/game/owned.h b/source/game/owned.h index d6e4348..9b9d99c 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -39,6 +39,8 @@ public: requires std::is_base_of_v Owned &operator=(Owned &&other) { assign(std::move(other)); return *this; } + Owned &operator=(std::nullptr_t); + ~Owned() { destroy(); } private: @@ -83,6 +85,14 @@ Owned::Owned(Handle

parent, Args &&... args) } } +template +Owned &Owned::operator=(std::nullptr_t) +{ + destroy(); + this->ptr = nullptr; + return *this; +} + template template void Owned::assign(Owned &&other)