HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Namespaces | Concepts | Macros | Functions
assert.hpp File Reference

Utilities to assert and bound check. More...

#include "architecture.hpp"
#include "debugger.hpp"
#include "utility.hpp"
#include "type_traits.hpp"
#include "exception.hpp"
#include <exception>
#include <ranges>

Go to the source code of this file.

Namespaces

namespace  v1
 DOXYGEN BUG.
 

Concepts

concept  v1::bound_check_range_helper
 

Macros

#define hi_assert(expression)
 Assert if expression is true.
 
#define hi_assert_or_return(x, y)
 Assert if an expression is true.
 
#define hi_assert_bounds(x, ...)
 
#define hi_assert_not_null(x)
 Assert if an expression is not nullptr.
 
#define hi_axiom(expression)   hi_assert(expression)
 Specify an axiom; an expression that is true.
 
#define hi_axiom_not_null(expression)   hi_assert_not_null(expression)
 Assert if an expression is not nullptr.
 
#define hi_no_default()   [[unlikely]] hi_debug_abort()
 This part of the code should not be reachable, unless a programming bug.
 
#define hi_static_no_default()
 This part of the code should not be reachable, unless a programming bug.
 
#define hi_not_implemented()   [[unlikely]] hi_debug_abort();
 This part of the code has not been implemented yet.
 
#define hi_static_not_implemented()   hi_static_no_default()
 This part of the code has not been implemented yet.
 

Functions

constexpr bool v1::bound_check (std::unsigned_integral auto index, std::unsigned_integral auto upper) noexcept
 Check if an unsigned index is less than the bound.
 
constexpr bool v1::bound_check (std::integral auto index, std::integral auto lower, std::integral auto upper) noexcept
 Check if an index is between the lower (inclusive) and upper (exclusive).
 
constexpr bool v1::bound_check (std::integral auto index, bound_check_range_helper auto &&range) noexcept
 Check if an index is within a range.
 

Detailed Description

Utilities to assert and bound check.

Macro Definition Documentation

◆ hi_assert

#define hi_assert ( expression)
Value:
do { \
if (not(expression)) { \
hi_set_terminate_message("assert: " hi_stringify(expression)); \
hi_debug_abort(); \
} \
} while (false)

Assert if expression is true.

Independent of built type this macro will always check and abort on fail.

Parameters
expressionThe expression to test.

◆ hi_assert_bounds

#define hi_assert_bounds ( x,
... )
Value:
do { \
if (not ::hi::bound_check(x, __VA_ARGS__)) { \
hi_set_terminate_message("assert bounds: " hi_stringify(x) " between " hi_stringify(__VA_ARGS__)); \
hi_debug_abort(); \
} \
} while (false)

◆ hi_assert_not_null

#define hi_assert_not_null ( x)
Value:
do { \
if (x == nullptr) { \
hi_set_terminate_message("assert not-null: " hi_stringify(x)); \
hi_debug_abort(); \
} \
} while (false)

Assert if an expression is not nullptr.

If the expression is not a nullptr then return from the function.

Parameters
xThe expression to test

◆ hi_assert_or_return

#define hi_assert_or_return ( x,
y )
Value:
if (!(x)) { \
[[unlikely]] return y; \
}

Assert if an expression is true.

If the expression is false then return from the function.

Parameters
xThe expression to test
yThe value to return from the current function.

◆ hi_axiom

#define hi_axiom ( expression)    hi_assert(expression)

Specify an axiom; an expression that is true.

An axiom is checked in debug mode, and is used as an optimization in release mode.

Parameters
expressionThe expression that is true.

◆ hi_axiom_not_null

#define hi_axiom_not_null ( expression)    hi_assert_not_null(expression)

Assert if an expression is not nullptr.

If the expression is not a nullptr then return from the function.

Parameters
xThe expression to test

◆ hi_no_default

#define hi_no_default ( )    [[unlikely]] hi_debug_abort()

This part of the code should not be reachable, unless a programming bug.

This function should be used in unreachable else statements or switch-default labels,

◆ hi_not_implemented

#define hi_not_implemented ( )    [[unlikely]] hi_debug_abort();

This part of the code has not been implemented yet.

This aborts the program.

◆ hi_static_no_default

#define hi_static_no_default ( )
Value:
[]<bool Flag = false>() \
{ \
static_assert(Flag); \
} \
()

This part of the code should not be reachable, unless a programming bug.

This function should be used in unreachable constexpr else statements.

◆ hi_static_not_implemented

#define hi_static_not_implemented ( )    hi_static_no_default()

This part of the code has not been implemented yet.

This function should be used in unreachable constexpr else statements.