summaryrefslogtreecommitdiff
path: root/lib/helpers.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-18 00:06:37 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-05-18 00:06:37 +0100
commitfcdca58617caf6a8c034a91588d6abb399be6b57 (patch)
treead77f8e954a2ed05cd26237a7c665f3adc82b9fe /lib/helpers.h
downloadmygrate-fcdca58617caf6a8c034a91588d6abb399be6b57.tar.bz2
mygrate-fcdca58617caf6a8c034a91588d6abb399be6b57.tar.xz
mygrate-fcdca58617caf6a8c034a91588d6abb399be6b57.zip
Initial commit, still lots to do!
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