diff --git a/luna/Check.h b/luna/Check.h index 4327a2be..429e65af 100644 --- a/luna/Check.h +++ b/luna/Check.h @@ -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) diff --git a/luna/Result.h b/luna/Result.h index 13dfd58a..ed99a04b 100644 --- a/luna/Result.h +++ b/luna/Result.h @@ -83,25 +83,25 @@ template 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 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 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; }