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