summaryrefslogtreecommitdiff
path: root/lib/helpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helpers.h')
-rw-r--r--lib/helpers.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/helpers.h b/lib/helpers.h
new file mode 100644
index 0000000..3a94ead
--- /dev/null
+++ b/lib/helpers.h
@@ -0,0 +1,35 @@
+#ifndef MYGRATE_HELPERS_H
+#define MYGRATE_HELPERS_H
+
+#include <concepts>
+#include <cstdint>
+#include <utility>
+
+namespace MyGrate {
+ template<std::integral I>
+ constexpr inline auto
+ bitslice(const I i, uint8_t offset, uint8_t size)
+ {
+ return (i >> offset) & ((1U << size) - 1U);
+ }
+
+ template<typename X, typename... P>
+ constexpr inline void
+ verify(bool expr, P &&... p)
+ {
+ if (!expr) {
+ throw X(std::forward<P...>(p)...);
+ }
+ }
+
+ template<typename T>
+ constexpr inline auto
+ mod100_extract(T & i)
+ {
+ const auto r {i % 100};
+ i /= 100;
+ return r;
+ }
+}
+
+#endif