summaryrefslogblamecommitdiffstats
path: root/src/common/bit_cast.h
blob: a32a063d1e9bfacfd3be0b987ca4ec918abd8213 (plain) (tree)





















                                                                                                  
// 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