Last active
April 13, 2020 17:02
-
-
Save danlark1/c6b10b98efe768b77f6d2cc99703ada3 to your computer and use it in GitHub Desktop.
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