Add a variant of check() that accepts an error message
This commit is contained in:
parent
a0c4bbe6f3
commit
bb92480aa3
@ -9,3 +9,5 @@ extern _noreturn bool __check_failed(const char* file, const char* line, const c
|
||||
#endif
|
||||
|
||||
#define check(expr) (expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr)
|
||||
#define expect(expr, message) \
|
||||
(expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message)
|
||||
|
@ -83,25 +83,25 @@ template <typename T> class Result
|
||||
|
||||
int error()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::error() called on a Result that holds a value");
|
||||
return m_error;
|
||||
}
|
||||
|
||||
Error release_error()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::release_error() called on a Result that holds a value");
|
||||
return {m_error};
|
||||
}
|
||||
|
||||
const char* error_string()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::error_string() called on a Result that holds a value");
|
||||
return ::error_string(m_error);
|
||||
}
|
||||
|
||||
T value()
|
||||
{
|
||||
check(has_value());
|
||||
expect(has_value(), "Result::value() called on a Result that holds an error");
|
||||
return m_storage.fetch_reference();
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ template <typename T> class Result
|
||||
|
||||
T release_value()
|
||||
{
|
||||
check(has_value());
|
||||
expect(has_value(), "Result::release_value() called on a Result that holds an error");
|
||||
T item = m_storage.fetch_reference();
|
||||
m_has_value = false;
|
||||
m_storage.destroy();
|
||||
@ -221,31 +221,31 @@ template <> class Result<void>
|
||||
|
||||
int error()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::error() called on a Result that holds a value");
|
||||
return m_error;
|
||||
}
|
||||
|
||||
Error release_error()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::release_error() called on a Result that holds a value");
|
||||
return {m_error};
|
||||
}
|
||||
|
||||
const char* error_string()
|
||||
{
|
||||
check(has_error());
|
||||
expect(has_error(), "Result::error_string() called on a Result that holds a value");
|
||||
return ::error_string(m_error);
|
||||
}
|
||||
|
||||
void value()
|
||||
{
|
||||
check(has_value());
|
||||
expect(has_value(), "Result::value() called on a Result that holds an error");
|
||||
return;
|
||||
}
|
||||
|
||||
void release_value()
|
||||
{
|
||||
check(has_value());
|
||||
expect(has_value(), "Result::release_value() called on a Result that holds an error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user