Add zeroInitialized to peripherals utility
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d03600fd54
commit
8e96588829
@ -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_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user