From 5829530652675d2f632efae6be2fe49d804897be Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Mon, 2 Feb 2026 08:13:26 +0100 Subject: [PATCH] Use optional for Singleton --- .../Sources/Utils/Include/Utils/Singleton.hpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp b/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp index 1d6fa9f..106eb70 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Singleton.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -32,7 +33,7 @@ class Singleton */ static constexpr TYPE& Instance() { - return *eastl::bit_cast(ms_instance.data()); + return ms_instance.value(); } class Lifetime @@ -78,9 +79,7 @@ class Singleton template static void Initialize(ARGS&&... p_args) { - new (ms_instance.data()) TYPE(eastl::forward(p_args)...); - - ms_initialized = true; + ms_instance.emplace(eastl::forward(p_args)...); } /** @@ -89,20 +88,13 @@ class Singleton */ static void Finalize() { - eastl::bit_cast(ms_instance.data())->~TYPE(); - - ms_initialized = false; + ms_instance.reset(); } /** * The singleton. */ - alignas(alignof(TYPE)) inline static eastl::array ms_instance; - - /** - * Is the singleton initialized? - */ - inline static bool ms_initialized = false; + inline static eastl::optional ms_instance; }; } // namespace Bigfoot #endif