Skip to content

Commit

Permalink
Fix check for the availability of std::bit_cast (AcademySoftwareFound…
Browse files Browse the repository at this point in the history
…ation#350)

See AcademySoftwareFoundation#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 <[email protected]>
  • Loading branch information
cary-ilm committed Jan 24, 2024
1 parent 8c5a12a commit b6ad9b0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/ImathTest/testFun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

#include <ImathFun.h>
#if __cplusplus >= 202002L
#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L
# include <bit>
#endif
#include <iostream>
Expand All @@ -20,20 +20,20 @@

using namespace std;

#if __cplusplus < 202002L
template <typename To, typename From>
static inline To
bit_cast (From from)
#if !defined(__cpp_lib_bit_cast) || __cpp_lib_bit_cast < 201806L
template <typename To, typename From>
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
Expand Down

0 comments on commit b6ad9b0

Please sign in to comment.