mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-29 15:23:01 -04:00
read_unaligned helper
"Things C++ should've had built-in 2 decades ago"
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
namespace dusk::helpers::alignment {
|
||||
|
||||
/**
|
||||
* Read data from an address that may not be aligned properly.
|
||||
* @tparam T Type of data to read.
|
||||
* @param ptr Address to read from.
|
||||
* @return The copied value.
|
||||
*/
|
||||
template <typename T> requires std::is_trivially_copyable_v<T>
|
||||
[[nodiscard]] constexpr T read_unaligned(u8 const* ptr) {
|
||||
T copy;
|
||||
memcpy(©, ptr, sizeof(T));
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user