From 540d95ae7e53693bb017d81a3504b6f7b86da724 Mon Sep 17 00:00:00 2001 From: TommiTheFirst Date: Mon, 16 Nov 2026 12:59:35 +0000 Subject: [PATCH] Replaced custom bitcast with std::bit_cast --- server/driver/xrt_cast.cpp | 27 --------------------------- server/driver/xrt_cast.h | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/server/driver/xrt_cast.cpp b/server/driver/xrt_cast.cpp index 947ef922..bd6175ea 100644 --- a/server/driver/xrt_cast.cpp +++ b/server/driver/xrt_cast.cpp @@ -19,35 +19,8 @@ #include "xrt_cast.h" #include "wivrn_packets.h" -#include #include -namespace -{ -template -Out do_cast(const In & in) -{ - Out res; - static_assert(sizeof(res) == sizeof(in)); - memcpy(&res, &in, sizeof(res)); - return res; -} -} // namespace - -#define XRT_CAST(in_type, out_type) \ - out_type xrt_cast(const in_type & in) \ - { \ - return do_cast(in); \ - } - -XRT_CAST(XrPosef, xrt_pose) -XRT_CAST(XrVector3f, xrt_vec3) -XRT_CAST(XrQuaternionf, xrt_quat) -XRT_CAST(XrFovf, xrt_fov) - -XRT_CAST(xrt_pose, XrPosef) -XRT_CAST(xrt_fov, XrFovf) - xrt_space_relation_flags from_pose_flags(uint8_t in_flags) { std::underlying_type_t flags{}; diff --git a/server/driver/xrt_cast.h b/server/driver/xrt_cast.h index 1ef6d00c..aee03c05 100644 --- a/server/driver/xrt_cast.h +++ b/server/driver/xrt_cast.h @@ -20,14 +20,23 @@ #pragma once #include "xrt/xrt_defines.h" +#include #include -xrt_pose xrt_cast(const XrPosef &); -xrt_vec3 xrt_cast(const XrVector3f &); -xrt_quat xrt_cast(const XrQuaternionf &); -xrt_fov xrt_cast(const XrFovf &); +#define XRT_CAST(in_type, out_type) \ + constexpr out_type xrt_cast(const in_type & in) noexcept \ + { \ + return std::bit_cast(in); \ + } -XrPosef xrt_cast(const xrt_pose &); -XrFovf xrt_cast(const xrt_fov &); +XRT_CAST(XrPosef, xrt_pose) +XRT_CAST(XrVector3f, xrt_vec3) +XRT_CAST(XrQuaternionf, xrt_quat) +XRT_CAST(XrFovf, xrt_fov) + +XRT_CAST(xrt_pose, XrPosef) +XRT_CAST(xrt_fov, XrFovf) + +#undef XRT_CAST xrt_space_relation_flags from_pose_flags(uint8_t in_flags);