BAN: ErrorOr<void> does not do an heap allocation anymore

This commit is contained in:
Bananymous 2023-01-12 00:11:54 +02:00
parent 296b6d8529
commit 67308c36ad
1 changed files with 9 additions and 8 deletions

View File

@ -49,24 +49,25 @@ public:
T& Value() { return *reinterpret_cast<T*>(m_data); } T& Value() { return *reinterpret_cast<T*>(m_data); }
private: private:
bool m_has_error; bool m_has_error = false;
void* m_data; void* m_data = nullptr;
}; };
template<> template<>
class ErrorOr<void> class ErrorOr<void>
{ {
public: public:
ErrorOr() : m_error(nullptr) { } ErrorOr() { }
ErrorOr(const Error& error) { m_error = new Error(error); } ErrorOr(const Error& error) : m_error(error) { }
~ErrorOr() { delete m_error; } ~ErrorOr() { }
bool IsError() const { return m_error; } bool IsError() const { return m_has_error; }
const Error& GetError() const { return *m_error; } const Error& GetError() const { return m_error; }
void Value() { } void Value() { }
private: private:
Error* m_error; Error m_error;
bool m_has_error = false;
}; };