Skip to content

Commit

Permalink
Fix BitCast to better reflect reference implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMax committed Dec 29, 2023
1 parent a6a1de4 commit 3bcafad
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/lexio/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ namespace Detail
* @see https://en.cppreference.com/w/cpp/numeric/bit_cast
*/
template <class TO, class FROM>
inline TO BitCast(const FROM &src) noexcept
inline std::enable_if_t<
sizeof(TO) == sizeof(FROM) && std::is_trivially_copyable<FROM>::value && std::is_trivially_copyable<TO>::value, TO>
BitCast(const FROM &src) noexcept
{
static_assert(sizeof(TO) == sizeof(FROM), "BitCast requires equal size.");
static_assert(std::is_trivially_copyable<FROM>::value, "BitCast FROM must be trivially copyable.");
static_assert(std::is_trivially_copyable<TO>::value, "BitCast TO must be trivially copyable.");
static_assert(std::is_trivially_constructible<TO>::value, "BitCast TO must be trivially constructible.");

TO dst;
Expand Down

0 comments on commit 3bcafad

Please sign in to comment.