From 67308c36ad726c1686599dcde9c0361037059113 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 12 Jan 2023 00:11:54 +0200 Subject: [PATCH] BAN: ErrorOr does not do an heap allocation anymore --- BAN/include/BAN/Errors.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/BAN/include/BAN/Errors.h b/BAN/include/BAN/Errors.h index 31da467c5b..3878ea4a25 100644 --- a/BAN/include/BAN/Errors.h +++ b/BAN/include/BAN/Errors.h @@ -49,24 +49,25 @@ public: T& Value() { return *reinterpret_cast(m_data); } private: - bool m_has_error; - void* m_data; + bool m_has_error = false; + void* m_data = nullptr; }; template<> class ErrorOr { public: - ErrorOr() : m_error(nullptr) { } - ErrorOr(const Error& error) { m_error = new Error(error); } - ~ErrorOr() { delete m_error; } + ErrorOr() { } + ErrorOr(const Error& error) : m_error(error) { } + ~ErrorOr() { } - bool IsError() const { return m_error; } - const Error& GetError() const { return *m_error; } + bool IsError() const { return m_has_error; } + const Error& GetError() const { return m_error; } void Value() { } private: - Error* m_error; + Error m_error; + bool m_has_error = false; };