Adds new Ensure helpers for clearer error messages.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -13,6 +13,41 @@
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(#expr, std::source_location::current()); \
|
||||
}
|
||||
|
||||
#define EnsureEquals(a, b) \
|
||||
if ((a) != (b)) { \
|
||||
std::stringstream error_ss; \
|
||||
error_ss << a << " was not equal to " << b; \
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(error_ss.str().c_str(), std::source_location::current()); \
|
||||
}
|
||||
|
||||
#define EnsureGreater(a, b) \
|
||||
if ((a) <= (b)) { \
|
||||
std::stringstream error_ss; \
|
||||
error_ss << a << " was not equal to " << b; \
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(error_ss.str().c_str(), std::source_location::current()); \
|
||||
}
|
||||
|
||||
#define EnsureGreaterOrEquals(a, b) \
|
||||
if ((a) < (b)) { \
|
||||
std::stringstream error_ss; \
|
||||
error_ss << a << " was not equal to " << b; \
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(error_ss.str().c_str(), std::source_location::current()); \
|
||||
}
|
||||
|
||||
#define EnsureLess(a, b) \
|
||||
if ((a) >= (b)) { \
|
||||
std::stringstream error_ss; \
|
||||
error_ss << a << " was not equal to " << b; \
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(error_ss.str().c_str(), std::source_location::current()); \
|
||||
}
|
||||
|
||||
#define EnsureLessOrEquals(a, b) \
|
||||
if ((a) > (b)) { \
|
||||
std::stringstream error_ss; \
|
||||
error_ss << a << " was not equal to " << b; \
|
||||
throw ArbUt::__ErrorHelpers::CreateEnsureError(error_ss.str().c_str(), std::source_location::current()); \
|
||||
}
|
||||
|
||||
/// @brief Ensures an expression is true for a range. The value in the range can be retrieved using ``item``.
|
||||
/// @ingroup Ensure
|
||||
#define EnsureForEach(iterator, assertion) \
|
||||
@@ -23,6 +58,11 @@
|
||||
#else
|
||||
// Ensure is empty if NO_ENSURE is defined.
|
||||
#define Ensure(expr) ;
|
||||
#define EnsureEquals(a, b) ;
|
||||
#define EnsureGreater(a, b) ;
|
||||
#define EnsureGreaterOrEquals(a, b) ;
|
||||
#define EnsureLess(a, b) ;
|
||||
#define EnsureLessOrEquals(a, b) ;
|
||||
#define EnsureForEach(iterator, assertion) ;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user