From ab41ef8a41760e882fa5c161f31b60e0a43f4f49 Mon Sep 17 00:00:00 2001 From: Damien L-G Date: Wed, 3 May 2023 17:00:18 -0400 Subject: [PATCH] Add implementation of bit_cast in --- core/src/Kokkos_BitManipulation.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/Kokkos_BitManipulation.hpp b/core/src/Kokkos_BitManipulation.hpp index 50cd92c986..04c9d4b2d2 100644 --- a/core/src/Kokkos_BitManipulation.hpp +++ b/core/src/Kokkos_BitManipulation.hpp @@ -20,6 +20,7 @@ #include #include #include // CHAR_BIT +#include //memcpy #include namespace Kokkos::Impl { @@ -98,6 +99,19 @@ inline constexpr bool is_standard_unsigned_integer_type_v = namespace Kokkos { +// +template +KOKKOS_FUNCTION std::enable_if_t && + std::is_trivially_copyable_v, + To> +bit_cast(From const& from) noexcept { + To to; + memcpy(&to, &from, sizeof(To)); + return to; +} +// + // template KOKKOS_FUNCTION constexpr std::enable_if_t, T> byteswap(