C++ Utilities
Loading...
Searching...
No Matches
assert.h

Assertion macros that are replacements for the standard assert macro, and which improve on it in various ways.
See the Assertions page for all the details. More...

Go to the source code of this file.

Macros

#define always_assert(cond, ...)
 An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.
#define always_assert_eq(lhs, rhs, ...)
 An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.
#define debug_assert(cond, ...)
 An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.
#define debug_assert_eq(a, b, ...)
 An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.
#define assert(cond, ...)
 An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.
#define assert_eq(lhs, rhs, ...)
 An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.

Detailed Description

Assertion macros that are replacements for the standard assert macro, and which improve on it in various ways.
See the Assertions page for all the details.

Macro Definition Documentation

◆ always_assert

#define always_assert ( cond,
... )
Value:
if (!(cond)) [[unlikely]] { failed(#cond, std::source_location::current() __VA_OPT__(, __VA_ARGS__)); }

An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.

The first argument is the condition to check, the (optional) rest are passed to std::format to form a custom extra message that is printed if the condition fails.

◆ always_assert_eq

#define always_assert_eq ( lhs,
rhs,
... )
Value:
if (!((lhs) == (rhs))) [[unlikely]] { \
failed_eq(#lhs, #rhs, (lhs), (rhs), std::source_location::current() __VA_OPT__(, __VA_ARGS__)); \
}

An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.

The first two arguments are the values to check for equality, the (optional) rest are passed to std::format to form a custom extra message that is printed if the values are not equal.

◆ assert

#define assert ( cond,
... )
Value:
always_assert(cond __VA_OPT__(, __VA_ARGS__))
#define always_assert(cond,...)
An assertion macro that checks a boolean condition cond. On failure, the assertion prints an error ...
Definition assert.h:42

An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.

NOTE: The assert macro expands to a no-op only when the NDEBUG flag is set.

The first argument is the condition to check, the (optional) rest are passed to std::format to form a custom extra message that is printed if the condition fails.

◆ assert_eq

#define assert_eq ( lhs,
rhs,
... )
Value:
always_assert_eq(lhs, rhs __VA_OPT__(, __VA_ARGS__))
#define always_assert_eq(lhs, rhs,...)
An assertion macro that checks the equality of two values lhs and rhs. On failure,...
Definition assert.h:52

An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.

NOTE: The assert_eq macro expands to a no-op only when the NDEBUG flag is set.

The first two arguments are the values to check for equality, the (optional) rest are passed to std::format to form a custom extra message that is printed if the values are not equal.

◆ debug_assert

#define debug_assert ( cond,
... )
Value:
void(0)

An assertion macro that checks a boolean condition cond.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the condition that failed.

NOTE: The debug_assert macro expands to a no-op unless the DEBUG flag is set.

The first argument is the condition to check, the (optional) rest are passed to std::format to form a custom extra message that is printed if the condition fails.

◆ debug_assert_eq

#define debug_assert_eq ( a,
b,
... )
Value:
void(0)

An assertion macro that checks the equality of two values lhs and rhs.
On failure, the assertion prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the assertion and a stringified version of the values that failed the equality check.

NOTE: The debug_assert_eq macro expands to a no-op unless the DEBUG flag is set.

The first two arguments are the values to check for equality, the (optional) rest are passed to std::format to form a custom extra message that is printed if the values are not equal.