From 3bcafadc4048724959e3b301b078bc13e054665e Mon Sep 17 00:00:00 2001 From: Lexi Mayfield Date: Fri, 29 Dec 2023 16:13:07 -0500 Subject: [PATCH] Fix BitCast to better reflect reference implementation --- include/lexio/core.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/lexio/core.hpp b/include/lexio/core.hpp index ed2b1cb..9cbe62e 100644 --- a/include/lexio/core.hpp +++ b/include/lexio/core.hpp @@ -118,11 +118,10 @@ namespace Detail * @see https://en.cppreference.com/w/cpp/numeric/bit_cast */ template -inline TO BitCast(const FROM &src) noexcept +inline std::enable_if_t< + sizeof(TO) == sizeof(FROM) && std::is_trivially_copyable::value && std::is_trivially_copyable::value, TO> +BitCast(const FROM &src) noexcept { - static_assert(sizeof(TO) == sizeof(FROM), "BitCast requires equal size."); - static_assert(std::is_trivially_copyable::value, "BitCast FROM must be trivially copyable."); - static_assert(std::is_trivially_copyable::value, "BitCast TO must be trivially copyable."); static_assert(std::is_trivially_constructible::value, "BitCast TO must be trivially constructible."); TO dst;