From 544e535b6e9a4162fa7dd8d2645f7e7d720c9a88 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 15 May 2023 23:38:13 +0300 Subject: [PATCH] Allow clearing an Owned by assigning nullptr --- source/game/owned.h | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) -- 2.45.2