common/cast_util: Declare BitCast and BitCastPointee with the noexcept specifier

std::bit_cast is also defined with the noexcept specifier, so we can do
the same here to match up with it and stay similar with the standard
library.
This commit is contained in:
Lioncash 2019-05-18 15:03:15 -04:00 committed by MerryMage
parent 9365487797
commit d9d59bc1f4

View file

@ -13,7 +13,7 @@ namespace Dynarmic::Common {
/// Reinterpret objects of one type as another by bit-casting between object representations. /// Reinterpret objects of one type as another by bit-casting between object representations.
template <class Dest, class Source> template <class Dest, class Source>
inline Dest BitCast(const Source& source) { inline Dest BitCast(const Source& source) noexcept {
static_assert(sizeof(Dest) == sizeof(Source), "size of destination and source objects must be equal"); static_assert(sizeof(Dest) == sizeof(Source), "size of destination and source objects must be equal");
static_assert(std::is_trivially_copyable_v<Dest>, "destination type must be trivially copyable."); static_assert(std::is_trivially_copyable_v<Dest>, "destination type must be trivially copyable.");
static_assert(std::is_trivially_copyable_v<Source>, "source type must be trivially copyable"); static_assert(std::is_trivially_copyable_v<Source>, "source type must be trivially copyable");
@ -26,7 +26,7 @@ inline Dest BitCast(const Source& source) {
/// Reinterpret objects of any arbitrary type as another type by bit-casting between object representations. /// Reinterpret objects of any arbitrary type as another type by bit-casting between object representations.
/// Note that here we do not verify if source has enough bytes to read from. /// Note that here we do not verify if source has enough bytes to read from.
template <class Dest, class SourcePtr> template <class Dest, class SourcePtr>
inline Dest BitCastPointee(const SourcePtr source) { inline Dest BitCastPointee(const SourcePtr source) noexcept {
static_assert(sizeof(SourcePtr) == sizeof(void*), "source pointer must have size of a pointer"); static_assert(sizeof(SourcePtr) == sizeof(void*), "source pointer must have size of a pointer");
static_assert(std::is_trivially_copyable_v<Dest>, "destination type must be trivially copyable."); static_assert(std::is_trivially_copyable_v<Dest>, "destination type must be trivially copyable.");