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  hi
 geometry/margins.hpp
 
namespace  hi::v1
 The HikoGUI API version 1.
 

Concepts

concept  hi::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 __VA_OPT__(, ) __VA_ARGS__)
 Specify an axiom; an expression that is true.
 
#define hi_axiom_not_null(expression, ...)   hi_assert_not_null(expression __VA_OPT__(, ) __VA_ARGS__)
 Assert if an expression is not nullptr.
 
#define hi_no_default(...)   [[unlikely]] hi_debug_abort("Reached no-default:" __VA_ARGS__)
 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("Not implemented: " __VA_ARGS__);
 This part of the code has not been implemented yet.
 
#define hi_static_not_implemented(...)   hi_static_no_default("Not implemented: " __VA_ARGS__)
 This part of the code has not been implemented yet.
 

Functions

constexpr bool hi::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 hi::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 hi::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_debug_abort("assert: " __VA_ARGS__ " (" hi_stringify(expression) ")"); \
} \
} 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.
...A string-literal explaining the reason why this assert exists.

◆ hi_assert_bounds

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

◆ hi_assert_not_null

#define hi_assert_not_null ( x,
... )
Value:
do { \
if (x == nullptr) { \
hi_debug_abort("assert not-null: " __VA_ARGS__ " (" hi_stringify(x) ")"); \
} \
} 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
...A string-literal as the reason why the not-null check exists.

◆ 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 __VA_OPT__(, ) __VA_ARGS__)

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.
...A string-literal as the reason why the axiom exists.

◆ hi_axiom_not_null

#define hi_axiom_not_null ( expression,
... )   hi_assert_not_null(expression __VA_OPT__(, ) __VA_ARGS__)

Assert if an expression is not nullptr.

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

Parameters
xThe expression to test
...A string-literal as the reason why the not-null check exists.

◆ hi_no_default

#define hi_no_default ( ...)    [[unlikely]] hi_debug_abort("Reached no-default:" __VA_ARGS__)

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,

Parameters
...A string-literal as the reason why the no-default exists.

◆ hi_not_implemented

#define hi_not_implemented ( ...)    [[unlikely]] hi_debug_abort("Not implemented: " __VA_ARGS__);

This part of the code has not been implemented yet.

This aborts the program.

Parameters
...A string-literal as the reason why this it not implemented.

◆ hi_static_no_default

#define hi_static_no_default ( ...)
Value:
[]<bool Flag = false>() \
{ \
static_assert(Flag, "No default: " __VA_ARGS__); \
} \
()

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

This function should be used in unreachable constexpr else statements.

Parameters
...A string-literal as the reason why the no-default exists.

◆ hi_static_not_implemented

#define hi_static_not_implemented ( ...)    hi_static_no_default("Not implemented: " __VA_ARGS__)

This part of the code has not been implemented yet.

This function should be used in unreachable constexpr else statements.

Parameters
...A string-literal as the reason why this it not implemented.