From bf6d15015a2e1a906c3245ccbcf936dc4ade40e7 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 2 Jan 2024 01:27:43 -0500 Subject: [PATCH] typecast --- include/blt/std/memory_util.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/blt/std/memory_util.h b/include/blt/std/memory_util.h index b7e2e8b..f3bf2d7 100644 --- a/include/blt/std/memory_util.h +++ b/include/blt/std/memory_util.h @@ -32,9 +32,9 @@ #define SWAP32(val) bswap_32(val) #define SWAP64(val) bswap_64(val) #if __cplusplus >= 202002L - + #include - + #define ENDIAN_LOOKUP(little_endian) (std::endian::native == std::endian::little && !little_endian) || \ (std::endian::native == std::endian::big && little_endian) #else @@ -109,6 +109,15 @@ namespace blt::mem return prev_size * 2; return prev_size + default_allocation_block; } + + template + inline static R type_cast(T type) + { + static_assert(sizeof(T) == sizeof(R)); + R r; + std::memcpy(&r, &type, sizeof(type)); + return r; + } } #endif //BLT_MEMORY_UTIL_H