summaryrefslogtreecommitdiff
path: root/include/libHX/defs.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libHX/defs.h')
-rw-r--r--include/libHX/defs.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/libHX/defs.h b/include/libHX/defs.h
index 1ace518..49ca7d1 100644
--- a/include/libHX/defs.h
+++ b/include/libHX/defs.h
@@ -10,8 +10,8 @@
# endif
# ifndef containerof
# include <cstddef>
-# define containerof(var, type, member) reinterpret_cast<type *>( \
- reinterpret_cast<char *>(var) - offsetof(type, member))
+# include <type_traits>
+# define containerof(var, T, member) reinterpret_cast<std::conditional<std::is_const<std::remove_pointer<decltype(var)>::type>::value, std::add_const<T>::type, T>::type *>(reinterpret_cast<std::conditional<std::is_const<std::remove_pointer<decltype(var)>::type>::value, const char, char>::type *>(var) - offsetof(T, member))
# endif
# ifndef static_cast
# define static_cast(T, x) static_cast<T>(x)