From 3f2e605dd12e91f81dd8debf46e69accab3aa1d0 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 20 Nov 2020 01:52:37 -0300 Subject: common/bit_cast: Add function matching std::bit_cast without constexpr Add a std::bit_cast-like function archiving the same runtime results as the standard function, without compile time support. This allows us to use bit_cast while we wait for compiler support, it can be trivially replaced in the future. --- src/common/bit_cast.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/common/bit_cast.h (limited to 'src/common/bit_cast.h') 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 +#include + +namespace Common { + +template +[[nodiscard]] std::enable_if_t && + std::is_trivially_copyable_v, + To> +BitCast(const From& src) noexcept { + To dst; + std::memcpy(&dst, &src, sizeof(To)); + return dst; +} + +} // namespace Common -- cgit v1.2.3