This commit is contained in:
Бранимир Караџић
2024-03-19 15:32:34 -07:00
parent dc3bf2990e
commit f433d1c4c3
2 changed files with 9 additions and 9 deletions

View File

@@ -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 <typename To, typename From>
constexpr To bit_cast(const From& value) noexcept;
template <typename Ty, typename FromT>
constexpr Ty bit_cast(const FromT& _from);
/// Copy memory block.
///

View File

@@ -147,14 +147,14 @@ namespace bx
return _a && !(_a & (_a - 1) );
}
template <typename To, typename From>
inline constexpr To bit_cast(const From& value) noexcept
template <typename Ty, typename FromT>
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<To>(), "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<Ty>(), "Destination target must be trivially constructible.");
Ty to;
bx::memCopy(&to, &_from, sizeof(Ty) );
return to;
}
} // namespace bx