mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 14:58:27 +00:00
created FromBitsUnchecked memcpy wrapper
This commit is contained in:
@@ -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>;
|
||||
|
@@ -54,6 +54,7 @@ struct AssetStream : std::istream {
|
||||
}
|
||||
|
||||
operator bool() {
|
||||
// NEED TO FIX THIS
|
||||
return reinterpret_cast<AssetMemoryBuffer*>(rdbuf())->m_Success;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user