From b6ad9b07a7511cc425d44391ab9fe3b6b415d29d Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Thu, 12 Oct 2023 16:06:10 -0400 Subject: [PATCH] Fix check for the availability of std::bit_cast (#350) See #346: Checking for the language version is not going to help for incomplete libraries such as on Apple or Android. This fixes this by using the bit_cast-specific macro. Signed-off-by: Cary Phillips --- src/ImathTest/testFun.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ImathTest/testFun.cpp b/src/ImathTest/testFun.cpp index 483b6ac3..758ead2d 100644 --- a/src/ImathTest/testFun.cpp +++ b/src/ImathTest/testFun.cpp @@ -8,7 +8,7 @@ #endif #include -#if __cplusplus >= 202002L +#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L # include #endif #include @@ -20,20 +20,20 @@ using namespace std; -#if __cplusplus < 202002L - template - static inline To - bit_cast (From from) +#if !defined(__cpp_lib_bit_cast) || __cpp_lib_bit_cast < 201806L +template +static inline To +bit_cast (From from) +{ + static_assert (sizeof (From) == sizeof (To), "Type sizes do not match"); + union { - static_assert (sizeof (From) == sizeof (To), "Type sizes do not match"); - union - { - From f; - To t; - } u; - u.f = from; - return u.t; - } + From f; + To t; + } u; + u.f = from; + return u.t; +} #endif void