arrays helper

This commit is contained in:
Matthew Kennedy 2022-07-16 22:15:59 -07:00
parent 8fcca4c0ce
commit de737f4746
1 changed files with 23 additions and 0 deletions

View File

@ -39,3 +39,26 @@ constexpr void copyArrayPartial(TElement (&dest)[NDest], const TElement (&src)[N
dest[i] = src[i];
}
}
namespace efi
{
template <typename T, size_t N>
constexpr size_t size(const T(&)[N]) {
return N;
}
// Zero the passed object
template <typename T>
constexpr void clear(T* obj) {
// The cast to void* is to prevent errors like:
// clearing an object of non-trivial type 'struct persistent_config_s'; use assignment or value-initialization instead
// This is technically wrong, but we know config objects only ever actually
// contain integral types, though they may be wrapped in a scaled_channel
memset(reinterpret_cast<void*>(obj), 0, sizeof(T));
}
template <typename T>
constexpr void clear(T& obj) {
clear(&obj);
}
} // namespace efi