11#include "exception.hpp"
18namespace hi {
inline namespace v1 {
26[[nodiscard]]
constexpr bool bound_check(std::unsigned_integral
auto index, std::unsigned_integral
auto upper)
noexcept
28 using value_type = common_integer_t<
decltype(index),
decltype(upper)>;
30 auto index_ =
static_cast<value_type
>(index);
31 auto upper_ =
static_cast<value_type
>(upper);
32 return index_ < upper_;
43[[nodiscard]]
constexpr bool bound_check(std::integral
auto index, std::integral
auto lower, std::integral
auto upper)
noexcept
45 using value_type = common_integer_t<
decltype(index),
decltype(lower),
decltype(upper)>;
47 auto index_ =
static_cast<value_type
>(index);
48 auto lower_ =
static_cast<value_type
>(lower);
49 auto upper_ =
static_cast<value_type
>(upper);
52 return index_ >= lower_ and index_ < upper_;
55template<
typename Context>
58 std::ranges::size(range)
59 } -> std::unsigned_integral;
68[[nodiscard]]
constexpr bool bound_check(std::integral
auto index, bound_check_range_helper
auto&& range)
noexcept
70 static_assert(
sizeof(index) <=
sizeof(
size_t));
72 if constexpr (std::is_signed_v<std::decay_t<
decltype(index)>>) {
78 return static_cast<size_t>(index) < std::ranges::size(range);
87#define hi_assert(expression, ...) \
89 if (not(expression)) { \
90 hi_debug_abort("assert: " __VA_ARGS__ " (" hi_stringify(expression) ")"); \
100#define hi_assert_or_return(x, y) \
102 [[unlikely]] return y; \
105#define hi_assert_bounds(x, ...) \
107 if (not ::hi::bound_check(x, __VA_ARGS__)) { \
108 hi_debug_abort("assert bounds: " hi_stringify(x) " between " hi_stringify(__VA_ARGS__)); \
118#define hi_assert_not_null(x, ...) \
120 if (x == nullptr) { \
121 hi_debug_abort("assert not-null: " __VA_ARGS__ " (" hi_stringify(x) ")"); \
133#define hi_axiom(expression, ...) hi_assert(expression __VA_OPT__(, ) __VA_ARGS__)
141#define hi_axiom_not_null(expression, ...) hi_assert_not_null(expression __VA_OPT__(, ) __VA_ARGS__)
148#define hi_no_default(...) [[unlikely]] hi_debug_abort("Reached no-default:" __VA_ARGS__)
158#define hi_axiom(expression, ...) hi_assume(expression)
166#define hi_axiom_not_null(expression, ...) hi_assume(expression != nullptr)
173#define hi_no_default(...) hi_unreachable()
181#define hi_static_no_default(...) \
182 []<bool Flag = false>() \
184 static_assert(Flag, "No default: " __VA_ARGS__); \
193#define hi_not_implemented(...) [[unlikely]] hi_debug_abort("Not implemented: " __VA_ARGS__);
200#define hi_static_not_implemented(...) hi_static_no_default("Not implemented: " __VA_ARGS__)
Utilities to interact with the debugger this application runs under.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
Utilities used by the HikoGUI library itself.
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
DOXYGEN BUG.
Definition algorithm.hpp:15
geometry/margins.hpp
Definition assert.hpp:18
constexpr bool bound_check(std::unsigned_integral auto index, std::unsigned_integral auto upper) noexcept
Check if an unsigned index is less than the bound.
Definition assert.hpp:26