#pragma once #include #include namespace std { #ifndef __cpp_lib_bit_cast #define __cpp_lib_bit_cast 201806L /// Create a value of type `To` from the bits of `from`. template requires (sizeof(To) == sizeof(From)) && std::is_trivially_copyable_v && std::is_trivially_copyable_v [[nodiscard]] constexpr To bit_cast(const From& from) noexcept { #if __has_builtin(__builtin_bit_cast) return __builtin_bit_cast(To, from); #else static_assert(std::is_trivially_constructible_v); To to; std::memcpy(&to, &from, sizeof(To)); return to; #endif } #endif // __cpp_lib_bit_cast } // namespace std