GF2++
Loading...
Searching...
No Matches
assert.h

Macros that improve on standard assert.
See the Assertions page for all the details. More...

Go to the source code of this file.

Namespaces

namespace  gf2
 The namespace for the gf2 library.

Macros

#define gf2_always_assert(expr, ...)
 A confirmation macro that checks a boolean condition cond.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the condition that failed.
#define gf2_always_assert_eq(a, b, ...)
 A confirmation macro that checks the equality of two values lhs and rhs.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the values that failed the equality check.
#define gf2_debug_assert(cond, ...)
 A confirmation macro that checks a boolean condition cond.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the condition that failed.
#define gf2_debug_assert_eq(a, b, ...)
 A confirmation macro that checks the equality of two values lhs and rhs.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the values that failed the equality check.
#define gf2_assert(cond, ...)
 A confirmation macro that checks a boolean condition cond.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the condition that failed.
#define gf2_assert_eq(lhs, rhs, ...)
 A confirmation macro that checks the equality of two values lhs and rhs.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation and a stringified version of the values that failed the equality check.

Variables

static auto gf2::exit_on_assert_failure = true
 By default, all failed confirmations exit the program.
You can set this variable to false to prevent this behavior (useful for unit tests).

Detailed Description

Macros that improve on standard assert.
See the Assertions page for all the details.

Macro Definition Documentation

◆ gf2_always_assert

#define gf2_always_assert ( expr,
... )
Value:
if (!(expr)) [[unlikely]] { gf2::assert_failed(#expr, std::source_location::current() __VA_OPT__(, __VA_ARGS__)); }

A confirmation macro that checks a boolean condition cond.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation 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.

◆ gf2_always_assert_eq

#define gf2_always_assert_eq ( a,
b,
... )
Value:
if (!((a) == (b))) [[unlikely]] { \
gf2::assert_eq_failed(#a, #b, (a), (b), std::source_location::current() __VA_OPT__(, __VA_ARGS__)); \
}

A confirmation macro that checks the equality of two values lhs and rhs.
On failure, the confirmation prints an error message and exits the program with a non-zero status code. The message always includes the source code location of the confirmation 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.

◆ gf2_assert

#define gf2_assert ( cond,
... )
Value:
gf2_always_assert(cond __VA_OPT__(, __VA_ARGS__))
#define gf2_always_assert(expr,...)
A confirmation macro that checks a boolean condition cond. On failure, the confirmation prints an e...
Definition assert.h:41

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

Note
The gf2_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.

◆ gf2_assert_eq

#define gf2_assert_eq ( lhs,
rhs,
... )
Value:
gf2_always_assert_eq(lhs, rhs __VA_OPT__(, __VA_ARGS__))
#define gf2_always_assert_eq(a, b,...)
A confirmation macro that checks the equality of two values lhs and rhs. On failure,...
Definition assert.h:51

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

Note
The gf2_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.

◆ gf2_debug_assert

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

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

Note
The gf2_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.

◆ gf2_debug_assert_eq

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

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

Note
The gf2_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.