#pragma once #include #include namespace c10 { // Implementations of std::bit_cast() from C++ 20. // // This is a less sketchy version of reinterpret_cast. // // See https://en.cppreference.com/w/cpp/numeric/bit_cast for more // information as well as the source of our implementations. template std::enable_if_t< sizeof(To) == sizeof(From) && std::is_trivially_copyable_v && std::is_trivially_copyable_v, To> // constexpr support needs compiler magic bit_cast(const From& src) noexcept { static_assert( std::is_trivially_constructible_v, "This implementation additionally requires " "destination type to be trivially constructible"); To dst; std::memcpy(&dst, &src, sizeof(To)); return dst; } } // namespace c10