#pragma once #include #include template struct bit_cast_fn { template constexpr auto operator()(const From &source) const noexcept -> std:: enable_if_t && std::is_trivially_copyable_v, To> { static_assert(std::is_trivially_constructible_v, "Input type must be trivially constructible"); To destination; std::memcpy(std::addressof(destination), std::addressof(source), sizeof(To)); return destination; } }; template static constexpr auto bit_cast = bit_cast_fn{};