Make Result able to return an error string

This commit is contained in:
apio 2022-11-30 17:10:43 +01:00
parent fc0779a2f9
commit 1d51935d43

View File

@ -2,6 +2,7 @@
#include <Check.h>
#include <Move.h>
#include <PlacementNew.h>
#include <SystemError.h>
#include <Types.h>
struct Error
@ -92,6 +93,12 @@ template <typename T> class Result
return {m_error};
}
const char* error_string()
{
check(has_error());
return ::error_string(m_error);
}
T value()
{
check(has_value());
@ -224,6 +231,12 @@ template <> class Result<void>
return {m_error};
}
const char* error_string()
{
check(has_error());
return ::error_string(m_error);
}
void value()
{
check(has_value());
@ -242,7 +255,7 @@ template <> class Result<void>
};
// clang-format off
#define err Error{0}
#define err(x) Error{x}
// clang-format on
#define TRY(expr) \