diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-03-08 04:42:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 04:42:19 +0100 |
commit | b014fdacdbb19491b9169df7e987293b4e851481 (patch) | |
tree | a5ceb18ca49f21fa1c8dc4872b6f7b154fd73ca6 /src | |
parent | input_common: Minor typo issues (#9922) (diff) | |
parent | common: make BitCast constexpr (diff) | |
download | yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar.gz yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar.bz2 yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar.lz yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar.xz yuzu-b014fdacdbb19491b9169df7e987293b4e851481.tar.zst yuzu-b014fdacdbb19491b9169df7e987293b4e851481.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/bit_cast.h | 20 |
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 |