Added futurecpp.h
This commit is contained in:
@@ -3,6 +3,7 @@ set(headers
|
|||||||
src/espcrc32builder.h
|
src/espcrc32builder.h
|
||||||
src/esprandom.h
|
src/esprandom.h
|
||||||
src/espstrutils.h
|
src/espstrutils.h
|
||||||
|
src/futurecpp.h
|
||||||
src/lockhelper.h
|
src/lockhelper.h
|
||||||
src/lockingqueue.h
|
src/lockingqueue.h
|
||||||
src/recursivelockhelper.h
|
src/recursivelockhelper.h
|
||||||
|
29
src/futurecpp.h
Normal file
29
src/futurecpp.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
#include <cstring>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
// 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
|
Reference in New Issue
Block a user