Asserts module

Contents

Butano's assert system.

It can be enabled or disabled by overloading the definition of BN_CFG_ASSERT_ENABLED .

Note that these asserts can be used in constexpr contexts (is_constant_evaluated() returns true).

Files

file bn_assert.h
file bn_config_assert.h

Defines

#define BN_ASSERT(condition, ...)
#define BN_ERROR(...)
#define BN_CFG_ASSERT_ENABLED
#define BN_CFG_ASSERT_BUFFER_SIZE

Define documentation

#define BN_ASSERT(condition, ...)
#include <bn_assert.h>

Checks if the specified condition is true.

If it doesn't, the execution is stopped and diagnostic information is shown on the screen.

More information can be shown by passing it by argument.

Example:

BN_ASSERT(integer > 0, "Invalid integer: ", integer);

Custom parameter types are supported by overloading bn::ostringstream::operator<<.

Example:

bn::ostringstream& operator<<(bn::ostringstream& stream, const custom_type& custom_value)
{
    stream.append("custom_type: ");
    stream.append(custom_value.data);
    return stream;
}

Note that it can be used in constexpr contexts (is_constant_evaluated() returns true).

#define BN_ERROR(...)
#include <bn_assert.h>

If this is called, the execution is stopped and diagnostic information is shown on the screen.

More information can be shown by passing it by argument.

Example:

BN_ERROR("Invalid integer: ", integer);

Custom parameter types are supported by overloading bn::ostringstream::operator<<.

Example:

bn::ostringstream& operator<<(bn::ostringstream& stream, const custom_type& custom_value)
{
    stream.append("custom_type: ");
    stream.append(custom_value.data);
    return stream;
}

Note that it can be used in constexpr contexts (is_constant_evaluated() returns true).

#define BN_CFG_ASSERT_ENABLED

Specifies if asserts must be enabled or not.

#define BN_CFG_ASSERT_BUFFER_SIZE

Specifies the maximum size of the messages that can be displayed by an assert.