diff --git a/include/bx/bx.h b/include/bx/bx.h index 79eff13..728d2d8 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -215,8 +215,8 @@ namespace bx constexpr bool isPowerOf2(Ty _a); /// Returns a value of type To by reinterpreting the object representation of From. - template - constexpr To bit_cast(const From& value) noexcept; + template + constexpr Ty bit_cast(const FromT& _from); /// Copy memory block. /// diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index 46c6c7e..09a2ddb 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -147,14 +147,14 @@ namespace bx return _a && !(_a & (_a - 1) ); } - template - inline constexpr To bit_cast(const From& value) noexcept + template + inline constexpr Ty bit_cast(const FromT& _from) { - BX_STATIC_ASSERT(sizeof(To) == sizeof(From), "To and From must be the same size."); - BX_STATIC_ASSERT(isTriviallyConstructible(), "Destination target must be trivially constructible."); - To result; - bx::memCopy(&result, &value, sizeof(To)); - return result; + static_assert(sizeof(Ty) == sizeof(FromT), "Ty and FromT must be the same size."); + static_assert(isTriviallyConstructible(), "Destination target must be trivially constructible."); + Ty to; + bx::memCopy(&to, &_from, sizeof(Ty) ); + return to; } } // namespace bx