HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
assert.hpp
1// Copyright Take Vos 2020-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "architecture.hpp"
8#include "debugger.hpp"
9#include "utils.hpp"
10#include "utility.hpp"
11#include "type_traits.hpp"
12#include "exception.hpp"
13#include <exception>
14
15namespace hi::inline v1 {
16
17[[nodiscard]] bool bound_check(
18 std::unsigned_integral auto index,
19 std::unsigned_integral auto upper) noexcept
20{
21 using value_type = common_integer_t<decltype(index), decltype(upper)>;
22
23 auto index_ = static_cast<value_type>(index);
24 auto upper_ = static_cast<value_type>(upper);
25 return index_ < upper_;
26}
27
28[[nodiscard]] bool bound_check(
29 std::integral auto index,
30 std::integral auto lower,
31 std::integral auto upper) noexcept
32{
33 using value_type = common_integer_t<decltype(index), decltype(lower), decltype(upper)>;
34
35 auto index_ = static_cast<value_type>(index);
36 auto lower_ = static_cast<value_type>(lower);
37 auto upper_ = static_cast<value_type>(upper);
38
39 return index_ >= lower_ and index_ < upper_;
40}
41
47#define hi_assert(expression) \
48 do { \
49 if (not(expression)) { \
50 hi_debug_abort(); \
51 } \
52 } while (false)
53
60#define hi_assert_or_return(x, y) \
61 if (!(x)) { \
62 [[unlikely]] return y; \
63 }
64
65#define hi_bounds(x, ...) \
66 do { \
67 if (not bound_check(x, __VA_ARGS__) { \
68 hi_debug_abort(); \
69 } \
70 } while (false)
71
72
73#ifndef NDEBUG
80#define hi_axiom(expression) hi_assert(expression)
81
85#define hi_no_default() [[unlikely]] hi_debug_abort()
86
87#else
94#define hi_axiom(expression) hi_assume(expression)
95
99#define hi_no_default() hi_unreachable()
100#endif
101
105#define hi_static_no_default() \
106 []<bool Flag = false>() \
107 { \
108 static_assert(Flag); \
109 } \
110 ()
111
115#define hi_not_implemented() [[unlikely]] hi_debug_abort();
116
120#define hi_static_not_implemented() hi_static_no_default()
121
122
123
124
125} // namespace hi::inline v1
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