diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-11-20 05:52:37 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-11-20 05:52:37 +0100 |
commit | 3f2e605dd12e91f81dd8debf46e69accab3aa1d0 (patch) | |
tree | 0a28af05b8d34cfb2433bf4f478c982e23f38fb1 /src/common/bit_cast.h | |
parent | Merge pull request #4948 from lioncash/page-resize (diff) | |
download | yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar.gz yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar.bz2 yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar.lz yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar.xz yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.tar.zst yuzu-3f2e605dd12e91f81dd8debf46e69accab3aa1d0.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/bit_cast.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/bit_cast.h b/src/common/bit_cast.h new file mode 100644 index 000000000..a32a063d1 --- /dev/null +++ b/src/common/bit_cast.h @@ -0,0 +1,22 @@ +// Copyright 2020 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <cstring> +#include <type_traits> + +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; +} + +} // namespace Common |