diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-25 15:24:26 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-10-26 14:21:48 -0700 |
commit | 86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80 (patch) | |
tree | 2710c62fe71d5e0d2e228fba9c951a040c4dcddf /src/compat/rawmem.hpp | |
parent | 6800761863dd45b6055768febc6ace6a20120dc7 (diff) | |
download | tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.gz tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.bz2 tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.tar.xz tmwa-86395f53634b3ef1ce76a7f1e5edfdb61f8ffd80.zip |
Fix header ranking
Diffstat (limited to 'src/compat/rawmem.hpp')
-rw-r--r-- | src/compat/rawmem.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/compat/rawmem.hpp b/src/compat/rawmem.hpp index c271a56..66af204 100644 --- a/src/compat/rawmem.hpp +++ b/src/compat/rawmem.hpp @@ -22,6 +22,8 @@ #include <cstdint> #include <cstring> +#include <type_traits> + #include "fwd.hpp" @@ -49,4 +51,23 @@ void really_memset0(uint8_t *dest, size_t n) { memset(dest, '\0', n); } + +template<class T> +struct is_trivially_copyable +: std::integral_constant<bool, + // come back when GCC actually implements the public traits properly + __has_trivial_copy(T) + && __has_trivial_assign(T) + && __has_trivial_destructor(T)> +{}; + +template<class T> +void really_memzero_this(T *v) +{ + static_assert(is_trivially_copyable<T>::value, "only for mostly-pod types"); + static_assert(std::is_class<T>::value || std::is_union<T>::value, "Only for user-defined structures (for now)"); + memset(v, '\0', sizeof(*v)); +} +template<class T, size_t n> +void really_memzero_this(T (&)[n]) = delete; } // namespace tmwa |