From 5ef7c7a9e1e6681ce43fae217e0c3a1b846e6874 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 22 Oct 2022 19:04:53 +0300 Subject: [PATCH] Allow null handles to be created from nullptr --- source/game/handle.h | 5 +++-- source/game/root.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/game/handle.h b/source/game/handle.h index d384f35..2e544c7 100644 --- a/source/game/handle.h +++ b/source/game/handle.h @@ -23,13 +23,14 @@ protected: public: Handle() = default; - - static Handle from_object(T *o) { Handle h; h.ptr = o; return h; } + Handle(nullptr_t) { } template requires std::is_base_of_v Handle(const Handle &other): ptr(other.ptr) { } + static Handle from_object(T *o) { Handle h; h.ptr = o; return h; } + T *get() const { return ptr; } T &operator*() const { return *ptr; } T *operator->() const { return ptr; } diff --git a/source/game/root.h b/source/game/root.h index f4ed18e..4f7ea76 100644 --- a/source/game/root.h +++ b/source/game/root.h @@ -13,7 +13,7 @@ private: Stage &stage; public: - Root(Stage &s): Entity(Handle()), stage(s) { } + Root(Stage &s): Entity(nullptr), stage(s) { } Stage &get_stage() const { return stage; } }; -- 2.43.0