]> git.tdb.fi Git - libs/game.git/commitdiff
Allow clearing an Owned by assigning nullptr
authorMikko Rasa <tdb@tdb.fi>
Mon, 15 May 2023 20:38:13 +0000 (23:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 15 May 2023 20:38:35 +0000 (23:38 +0300)
source/game/owned.h

index d6e4348fdd45b43c65e460182f7de839b01b16a8..9b9d99cdedcca02d59975f2f62a4dc737dbceba4 100644 (file)
@@ -39,6 +39,8 @@ public:
                requires std::is_base_of_v<T, U>
        Owned &operator=(Owned<U> &&other) { assign(std::move(other)); return *this; }
 
+       Owned &operator=(std::nullptr_t);
+
        ~Owned() { destroy(); }
 
 private:
@@ -83,6 +85,14 @@ Owned<T>::Owned(Handle<P> parent, Args &&... args)
        }
 }
 
+template<typename T>
+Owned<T> &Owned<T>::operator=(std::nullptr_t)
+{
+       destroy();
+       this->ptr = nullptr;
+       return *this;
+}
+
 template<typename T>
 template<typename U>
 void Owned<T>::assign(Owned<U> &&other)