bit_cast.h 440 B

1234567891011121314151617181920212223
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <version>
  5. #ifdef __cpp_lib_bit_cast
  6. #include <bit>
  7. #endif
  8. namespace Common {
  9. template <typename To, typename From>
  10. constexpr inline To BitCast(const From& from) {
  11. #ifdef __cpp_lib_bit_cast
  12. return std::bit_cast<To>(from);
  13. #else
  14. return __builtin_bit_cast(To, from);
  15. #endif
  16. }
  17. } // namespace Common