From b4b12914a130c7896d9818df429b704fb61a6ff9 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Mon, 3 Dec 2018 14:18:38 -0800 Subject: [PATCH] Add bitcast to utils. --- libs/utils/include/utils/algorithm.h | 12 ++++++++++++ tools/filamesh/src/main.cpp | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/utils/include/utils/algorithm.h b/libs/utils/include/utils/algorithm.h index 988d1b9d07..c05c6d43b7 100644 --- a/libs/utils/include/utils/algorithm.h +++ b/libs/utils/include/utils/algorithm.h @@ -255,6 +255,18 @@ RandomAccessIterator partition_point( return first; } +template +typename std::enable_if_t< + (sizeof(To) == sizeof(From)) && + std::is_trivially_copyable::value && + std::is_trivial::value, + // this implementation requires that To is trivially default constructible + To> +// constexpr support needs compiler magic +bit_cast(const From &src) noexcept { + return reinterpret_cast(src); +} + } // namespace utils #endif // TNT_UTILS_ALGORITHM_H diff --git a/tools/filamesh/src/main.cpp b/tools/filamesh/src/main.cpp index 99c5d4ebb0..d3e3eb5179 100644 --- a/tools/filamesh/src/main.cpp +++ b/tools/filamesh/src/main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -50,11 +51,6 @@ Mesh g_mesh; float2 g_minUV = float2(std::numeric_limits::max()); float2 g_maxUV = float2(-std::numeric_limits::max()); -template -inline Dest bit_cast(const Source& source) { - return *reinterpret_cast(&source); -} - template static ushort2 convertUV(float2 uv) { if (SNORMUVS) {