Skip to content

Commit

Permalink
[bit] Use __builtin_bit_cast on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Apr 15, 2024
1 parent 6176c49 commit 6c28b0f
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions include/etl/_bit/bit_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@ template <typename To, typename From>
requires(detail::bit_castable_types<To, From>)
constexpr auto bit_cast(From const& src) noexcept -> To
{
#if __has_builtin(__builtin_bit_cast)
#if __has_builtin(__builtin_bit_cast) or (defined(_MSC_VER) and not defined(__clang__))
return __builtin_bit_cast(To, src);
#else
// This implementation additionally requires destination type to be
// trivially constructible
static_assert(is_trivially_constructible_v<To>);

To dst{};
detail::memcpy<char, etl::size_t>(&dst, &src, sizeof(To));
etl::detail::memcpy<char, etl::size_t>(&dst, &src, sizeof(To));
return dst;
#endif
}
Expand Down

0 comments on commit 6c28b0f

Please sign in to comment.