From: Mikko Rasa Date: Sun, 4 Dec 2022 21:32:05 +0000 (+0200) Subject: Add move constructor and assignment from Owned of derived type X-Git-Url: http://git.tdb.fi/?p=libs%2Fgame.git;a=commitdiff_plain;h=c71b8c2151e097f435c8f76ffa123cc71f9d12ec Add move constructor and assignment from Owned of derived type --- diff --git a/source/game/owned.h b/source/game/owned.h index 76a7552..a30f040 100644 --- a/source/game/owned.h +++ b/source/game/owned.h @@ -25,10 +25,23 @@ public: Owned(P *parent, Args &&... args): Owned(Handle

::from_object(parent), std::forward(args)...) { } Owned(Owned &&other): Handle(other) { other.ptr = nullptr; } - Owned &operator=(Owned &&other); + + template + requires std::is_base_of_v + Owned(Owned &&other): Handle(other) { other.ptr = nullptr; } + + Owned &operator=(Owned &&other) { assign(std::move(other)); return *this; } + + template + requires std::is_base_of_v + Owned &operator=(Owned &&other) { assign(std::move(other)); return *this; } + ~Owned() { destroy(); } private: + template + void assign(Owned &&); + template static Stage &get_stage(O &); @@ -68,14 +81,13 @@ Owned::Owned(Handle

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