summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorLiam <byteslice@airmail.cc>2023-03-08 01:53:32 +0100
committerLiam <byteslice@airmail.cc>2023-03-08 02:26:56 +0100
commit64dcb40db139ce1aa79dff16ce863a8d5389199f (patch)
tree4b58da704b35a1a221f5d83a8d0cf8dce495a3f1 /src/common
parentMerge pull request #9889 from Morph1984/time-is-ticking (diff)
downloadyuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar.gz
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar.bz2
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar.lz
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar.xz
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.tar.zst
yuzu-64dcb40db139ce1aa79dff16ce863a8d5389199f.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/bit_cast.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/common/bit_cast.h b/src/common/bit_cast.h
index 535148b4d..c6110c542 100644
--- a/src/common/bit_cast.h
+++ b/src/common/bit_cast.h
@@ -3,19 +3,21 @@
#pragma once
-#include <cstring>
-#include <type_traits>
+#include <version>
+
+#ifdef __cpp_lib_bit_cast
+#include <bit>
+#endif
namespace Common {
template <typename To, typename From>
-[[nodiscard]] std::enable_if_t<sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> &&
- std::is_trivially_copyable_v<To>,
- To>
-BitCast(const From& src) noexcept {
- To dst;
- std::memcpy(&dst, &src, sizeof(To));
- return dst;
+constexpr inline To BitCast(const From& from) {
+#ifdef __cpp_lib_bit_cast
+ return std::bit_cast<To>(from);
+#else
+ return __builtin_bit_cast(To, from);
+#endif
}
} // namespace Common