11#include "exception.hpp"
18namespace hi::inline
v1 {
26[[nodiscard]]
constexpr bool bound_check(std::unsigned_integral
auto index, std::unsigned_integral
auto upper)
noexcept
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;
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);
86#define hi_assert(expression) \
88 if (not(expression)) { \
89 hi_set_terminate_message("assert: " 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_set_terminate_message("assert bounds: " hi_stringify(x) " between " hi_stringify(__VA_ARGS__)); \
118#define hi_assert_not_null(x) \
120 if (x == nullptr) { \
121 hi_set_terminate_message("assert not-null: " hi_stringify(x)); \
133#define hi_axiom(expression) hi_assert(expression)
140#define hi_axiom_not_null(expression) hi_assert_not_null(expression)
145#define hi_no_default() [[unlikely]] hi_debug_abort()
154#define hi_axiom(expression) hi_assume(expression)
161#define hi_axiom_not_null(expression) hi_assume(expression != nullptr)
166#define hi_no_default() hi_unreachable()
172#define hi_static_no_default() \
173 []<bool Flag = false>() \
175 static_assert(Flag); \
182#define hi_not_implemented() [[unlikely]] hi_debug_abort();
187#define hi_static_not_implemented() hi_static_no_default()
#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
common_integer< L, R... >::type common_integer_t
Get an integer type that will fit all values from all template parameters.
Definition type_traits.hpp:304
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