diff --git a/Peripherals/Inc/peripherals_utility.hpp b/Peripherals/Inc/peripherals_utility.hpp index b708d34..077b683 100644 --- a/Peripherals/Inc/peripherals_utility.hpp +++ b/Peripherals/Inc/peripherals_utility.hpp @@ -9,6 +9,8 @@ #define PERIPHERALS_UTILITY_HPP_ #include +#include +#include namespace Peripherals { @@ -54,6 +56,17 @@ T ByteToTypeLE(const std::uint8_t a[N]) return t; } +template +constexpr T zeroInitialized() +{ + static_assert(std::is_trivially_default_constructible::value, "Struct is not trivially default constructible."); + + T t; + std::memset(&t, 0, sizeof(T)); + + return t; +} + }// namespace Peripherals #endif /* PERIPHERALS_UTILITY_HPP_ */