#pragma once #include #include template inline T unalignedLoad(const void * address) { T res {}; memcpy(&res, address, sizeof(res)); return res; } /// We've had troubles before with wrong store size due to integral promotions /// (e.g., unalignedStore(dest, uint16_t + uint16_t) stores an uint32_t). /// To prevent this, make the caller specify the stored type explicitly. /// To disable deduction of T, wrap the argument type with std::enable_if. template inline void unalignedStore(void * address, const typename std::enable_if::type & src) { static_assert(std::is_trivially_copyable_v); memcpy(address, &src, sizeof(src)); }