Downgrade for old compiler

This commit is contained in:
2022-07-11 16:05:42 +02:00
parent 35e3a49a33
commit 941c631a5f
5 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,7 @@ set(headers
src/espcrc32builder.h
src/esprandom.h
src/espstrutils.h
src/futurecpp.h
src/lockhelper.h
src/lockingqueue.h
src/recursivelockhelper.h

View File

@ -10,6 +10,7 @@
#include <esp_log.h>
// 3rdparty lib includes
#include <futurecpp.h>
#include <fmt/core.h>
using namespace std::string_literals;

30
src/futurecpp.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
// system includes
#include <cstring>
#include <limits>
#include <type_traits>
// C++20 backports (until espressif finally updates their aged compiler suite)
namespace std {
template <class To, class From>
typename std::enable_if_t<
sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>,
To>
// constexpr support needs compiler magic
bit_cast(const From& src) noexcept
{
static_assert(std::is_trivially_constructible_v<To>,
"This implementation additionally requires destination type to be trivially constructible");
To dst;
std::memcpy(&dst, &src, sizeof(To));
return dst;
}
template <typename EnumT, typename = std::enable_if_t<std::is_enum<EnumT>{}>>
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
return static_cast<std::underlying_type_t<EnumT>>(e);
}
} // namespace std

View File

@ -9,6 +9,9 @@
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <futurecpp.h>
namespace espcpputils {
namespace {
constexpr const char * const TAG = "ESPCPPUTILS";

View File

@ -11,6 +11,7 @@
// 3rdparty lib includes
#include <fmt/core.h>
#include <futurecpp.h>
namespace espcpputils {
class websocket_client