From c71b8c2151e097f435c8f76ffa123cc71f9d12ec Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 4 Dec 2022 23:32:05 +0200 Subject: [PATCH] Add move constructor and assignment from Owned of derived type --- source/game/owned.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 -- 2.43.0