created FromBitsUnchecked memcpy wrapper

This commit is contained in:
jadebenn
2024-11-25 01:40:58 -06:00
parent 6fa719c679
commit 66fa3ff4ba
4 changed files with 28 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
// C++
#include <charconv>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <functional>
#include <optional>
@@ -152,6 +153,26 @@ namespace GeneralUtils {
char_pointer_hash
>;
/**
* A convenience wrapper around std::memcpy that creates a new object
* from the value representation of the provided bytes.Use when
* std::bit_cast is not applicable.
* @warning All restrictions of std::memcpy still apply. Accessing
* outside of the source object is undefined behavior.
* @param from The source of the value representation
* @returns A new object with the given value representation
*/
template <typename To, typename From>
[[nodiscard]]
inline To FromBitsUnchecked(const From* from) noexcept
requires (std::is_trivially_copyable_v<To>
&& std::is_trivially_copyable_v<From>)
{
To to{};
std::memcpy(&to, from, sizeof(To));
return to;
}
// Concept constraining to enum types
template <typename T>
concept Enum = std::is_enum_v<T>;

View File

@@ -54,6 +54,7 @@ struct AssetStream : std::istream {
}
operator bool() {
// NEED TO FIX THIS
return reinterpret_cast<AssetMemoryBuffer*>(rdbuf())->m_Success;
}
};