summaryrefslogtreecommitdiff
path: root/include/static_assert.hpp
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-01-28 09:31:59 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-01-28 19:04:05 -0400
commita88ef2fde041e5d733b5cbe2728b15ca149d1671 (patch)
treeb4b01c75a640810f6549c485a382242d25a19a97 /include/static_assert.hpp
Initial commit
Diffstat (limited to 'include/static_assert.hpp')
-rw-r--r--include/static_assert.hpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/include/static_assert.hpp b/include/static_assert.hpp
new file mode 100644
index 0000000..daccdd3
--- /dev/null
+++ b/include/static_assert.hpp
@@ -0,0 +1,35 @@
+// This file was taken from the Metroid Prime decompilation project.
+// https://github.com/PrimeDecomp/prime/blob/main/include/static_assert.hpp
+// C++98 static assert
+
+struct false_type {
+ static const int value = 0;
+};
+
+struct true_type {
+ static const int value = 1;
+};
+
+template < int A, int B >
+struct _n_is_equal : false_type {};
+
+template < int A >
+struct _n_is_equal< A, A > : true_type {};
+
+template < class T, int N >
+struct check_sizeof : _n_is_equal< sizeof(T), N > {};
+
+#ifdef __MWERKS__
+#ifndef offsetof
+typedef unsigned long size_t;
+#define offsetof(type, member) ((size_t) & (((type*)0)->member))
+#endif
+#define CHECK_SIZEOF(cls, size) extern int cls##_check[check_sizeof< cls, size >::value];
+#define NESTED_CHECK_SIZEOF(parent, cls, size) extern int cls##_check[check_sizeof< parent::cls, size >::value];
+#define CHECK_OFFSETOF(cls, member, offset) \
+ extern int cls##_check_offset##[_n_is_equal< offsetof(cls, member), offset >::value];
+#else
+#define CHECK_SIZEOF(cls, size)
+#define NESTED_CHECK_SIZEOF(parent, cls, size)
+#define CHECK_OFFSETOF(cls, member, offset)
+#endif