11#include "../macros.hpp"
12#include "debugger.hpp"
13#include "exception.hpp"
17hi_export_module(hikogui.utility.assert);
23namespace hi {
inline namespace v1 {
31hi_export [[nodiscard]]
constexpr bool bound_check(std::unsigned_integral
auto index, std::unsigned_integral
auto upper)
noexcept
33 using value_type = common_integer_t<
decltype(index),
decltype(upper)>;
35 hilet index_ =
static_cast<value_type
>(index);
36 hilet upper_ =
static_cast<value_type
>(upper);
37 return index_ < upper_;
40hi_export [[nodiscard]]
constexpr bool bound_check(std::unsigned_integral
auto index, std::signed_integral
auto upper)
noexcept
45 return bound_check(index,
static_cast<std::make_unsigned_t<decltype(upper)
>>(upper));
56hi_export [[nodiscard]]
constexpr bool bound_check(std::integral
auto index, std::integral
auto lower, std::integral
auto upper)
noexcept
58 using value_type = common_integer_t<
decltype(index),
decltype(lower),
decltype(upper)>;
60 auto index_ =
static_cast<value_type
>(index);
61 auto lower_ =
static_cast<value_type
>(lower);
62 auto upper_ =
static_cast<value_type
>(upper);
65 if (not(lower_ < upper_)) {
66 hi_debug_abort(
"bound_check() lower is greater than upper.");
69 hi_assume(lower_ < upper_);
72 return index_ >= lower_ and index_ < upper_;
75template<
typename Context>
78 std::ranges::size(range)
79 } -> std::unsigned_integral;
88hi_export [[nodiscard]]
constexpr bool bound_check(std::integral
auto index, bound_check_range_helper
auto&& range)
noexcept
90 static_assert(
sizeof(index) <=
sizeof(size_t));
92 if constexpr (std::is_signed_v<std::decay_t<
decltype(index)>>) {
98 return static_cast<size_t>(index) < std::ranges::size(range);
hi_warning_ignore_msvc(26472)
Definition int_carry.hpp:30
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
hi_export 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:31