20 if constexpr(!std::is_same_v<T, void>)
34inline void from_bytes(
const std::byte*
const srcBytes, T*
const out_dstValue)
36 static_assert(std::is_trivially_copyable_v<T>);
44 reinterpret_cast<std::byte*
>(out_dstValue));
48inline void to_bytes(
const T& srcValue, std::byte*
const out_dstBytes)
50 static_assert(std::is_trivially_copyable_v<T>);
55 reinterpret_cast<const std::byte*
>(&srcValue),
56 reinterpret_cast<const std::byte*
>(&srcValue) +
sizeof(T),
60template<std::
size_t N>
72 else if constexpr(N == 2)
74 std::uint16_t twoBytes;
76 twoBytes = std::byteswap(twoBytes);
79 else if constexpr(N == 4)
81 std::uint32_t fourBytes;
83 fourBytes = std::byteswap(fourBytes);
86 else if constexpr(N == 8)
88 std::uint64_t eightBytes;
90 eightBytes = std::byteswap(eightBytes);
95 std::reverse(bytes, bytes + N);
111 std::is_aggregate<T>,
113 std::is_trivially_destructible<T>,
115 std::is_trivially_default_constructible<T>,
116 std::is_trivially_copy_constructible<T>,
117 std::is_trivially_move_constructible<T>>>>;
124#if __cpp_lib_start_lifetime_as
125 return std::start_lifetime_as<T>(ptr);
135 std::is_trivially_copyable_v<T>
136#if __cpp_lib_is_implicit_lifetime
137 && std::is_implicit_lifetime_v<T>
143#if __cpp_lib_start_lifetime_as
144 return std::start_lifetime_as_array<T>(ptr, numArrayElements);
152 return std::launder(
static_cast<T*
>(std::memmove(ptr, ptr,
sizeof(T) * numArrayElements)));
#define PH_ASSERT(condition)
Definition assertion.h:49
#define PH_ASSERT_EQ(a, b)
Definition assertion.h:55
Definition memory.ipp:108
Low-level memory allocation routines.
void * allocate_aligned_memory(std::size_t numBytes, std::size_t alignmentInBytes)
Definition memory.cpp:27
The root for all renderer implementations.
Definition assertion.h:9
T * start_implicit_lifetime_as_array(void *ptr, std::size_t numArrayElements) noexcept
Wrapper for std::start_lifetime_as_array(). Primarily a fallback when C++23 is not available....
Definition memory.ipp:132
T * start_implicit_lifetime_as(void *ptr) noexcept
Wrapper for std::start_lifetime_as(). Primarily a fallback when C++23 is not available....
Definition memory.ipp:122
void from_bytes(const std::byte *srcBytes, T *out_dstValue)
Definition memory.ipp:34
std::unique_ptr< T, detail::AlignedMemoryDeleter > TAlignedMemoryUniquePtr
Definition memory.h:56
auto make_aligned_memory(std::size_t numBytes, std::size_t alignmentInBytes) -> TAlignedMemoryUniquePtr< T >
Create an aligned memory resource.
Definition memory.ipp:17
void reverse_bytes(std::byte *bytes)
Definition memory.ipp:61
void to_bytes(const T &srcValue, std::byte *out_dstBytes)
Definition memory.ipp:48