-
-
Save rightfold/a4122970bb4587d3bd01 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
struct type { | |
std::size_t size; | |
std::size_t alignment; | |
std::unordered_map<std::string, field> fields; | |
std::function<void(void*, void*)> move; | |
}; | |
struct field { | |
std::size_t size; | |
std::size_t offset; | |
template<typename T> | |
T read(void* objptr) { | |
static_assert(std::is_pod<T>()); | |
assert(sizeof(T) == size); | |
T result; | |
memcpy(&result, (char*)objptr + offset, size); | |
return result; | |
} | |
template<typename T> | |
void write(void* objptr, T value) { | |
static_assert(std::is_pod<T>()); | |
assert(sizeof(T) == size); | |
memcpy((char*)objptr + offset, &value, size); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment