1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-29 22:24:26 +00:00

Introduce bit_cast() backport (#2991)

This commit is contained in:
Oxan van Leeuwen
2022-01-04 10:14:57 +01:00
committed by GitHub
parent 26dd1f8532
commit e5775cf812
2 changed files with 32 additions and 13 deletions

View File

@@ -2,7 +2,8 @@
#include <cstring>
#include <cstdint>
#include <type_traits>
#include "esphome/core/helpers.h"
namespace esphome {
@@ -45,20 +46,12 @@ class ESPPreferences {
*/
virtual bool sync() = 0;
#ifndef USE_ESP8266
template<typename T, typename std::enable_if<std::is_trivially_copyable<T>::value, bool>::type = true>
#else
// esp8266 toolchain doesn't have is_trivially_copyable
template<typename T>
#endif
template<typename T, enable_if_t<is_trivially_copyable<T>::value, bool> = true>
ESPPreferenceObject make_preference(uint32_t type, bool in_flash) {
return this->make_preference(sizeof(T), type, in_flash);
}
#ifndef USE_ESP8266
template<typename T, typename std::enable_if<std::is_trivially_copyable<T>::value, bool>::type = true>
#else
template<typename T>
#endif
template<typename T, enable_if_t<is_trivially_copyable<T>::value, bool> = true>
ESPPreferenceObject make_preference(uint32_t type) {
return this->make_preference(sizeof(T), type);
}