Add zeroInitialized to peripherals utility
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Erki 2021-06-06 13:11:18 +03:00
parent d03600fd54
commit 8e96588829

View File

@ -9,6 +9,8 @@
#define PERIPHERALS_UTILITY_HPP_
#include <cstdint>
#include <cstring>
#include <type_traits>
namespace Peripherals
{
@ -54,6 +56,17 @@ T ByteToTypeLE(const std::uint8_t a[N])
return t;
}
template<typename T>
constexpr T zeroInitialized()
{
static_assert(std::is_trivially_default_constructible<T>::value, "Struct is not trivially default constructible.");
T t;
std::memset(&t, 0, sizeof(T));
return t;
}
}// namespace Peripherals
#endif /* PERIPHERALS_UTILITY_HPP_ */