This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class T> | |
T Deserialize(const void* memory) noexcept { | |
static_assert(std::is_trivially_copyable_v<T>); | |
T t; | |
memcpy(std::addressof(t), memory, sizeof(T)); | |
return t; | |
} | |
// std::remove_reference_t for non-deduced context to prevent such code to blow below: | |
// char first = f(); char second = g(); | |
// Serialize(first - second, to) (int will be deduced) | |
template <class T> | |
void Serialize(const std::remove_reference_t<T>& t, void* memory) noexcept { | |
static_assert(std::is_trivially_copyable_v<T>); | |
memcpy(to, std::addressof(t), sizeof(T)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment